Created
April 23, 2017 15:48
-
-
Save saibimajdi/2e829afaa707c45cfe6dc63047deac4f to your computer and use it in GitHub Desktop.
Mail sender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Mail; | |
using System.Web; | |
namespace MSPTunisia.Models | |
{ | |
public static class Mailer | |
{ | |
public static int SendEmail(string to, string subject, string body) | |
{ | |
SmtpClient client = new SmtpClient() | |
{ | |
Host = "smtp-mail.outlook.com", // if Gmail use : "smtp.gmail.com" | |
Port = 587, | |
EnableSsl = true | |
}; | |
client.Credentials = new NetworkCredential( | |
"SENDER_EMAIL", | |
"SENDER_EMAIL_PASSWORD"); | |
MailMessage mm = new MailMessage(); | |
mm.From = new MailAddress("SENDER_EMAIL"); | |
mm.To.Add(to); | |
mm.Subject = subject; | |
mm.Body = body; | |
client.Send(mm); | |
return 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment