Skip to content

Instantly share code, notes, and snippets.

@saibimajdi
Created April 23, 2017 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saibimajdi/2e829afaa707c45cfe6dc63047deac4f to your computer and use it in GitHub Desktop.
Save saibimajdi/2e829afaa707c45cfe6dc63047deac4f to your computer and use it in GitHub Desktop.
Mail sender
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