Skip to content

Instantly share code, notes, and snippets.

@axiak
Created September 17, 2015 15:03
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 axiak/e2af9ace364362e422a3 to your computer and use it in GitHub Desktop.
Save axiak/e2af9ace364362e422a3 to your computer and use it in GitHub Desktop.
using System.Net.Mail;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class TestClass {
public static void Main() {
string subject = "";
string body = "";
string host = "smtp.hubapi.com";
string username = "";
string password = "";
string recipientAddress = "some address";
string recipientName = "some name";
string fromAddress = "some address";
SmtpClient client;
MailMessage mail;
// Always validate the remote certificate chain
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
client = new SmtpClient(host, 587);
NetworkCredential basicCredential = new NetworkCredential(username, password);
client.UseDefaultCredentials = false;
client.Credentials = basicCredential;
client.EnableSsl = true;
mail = new MailMessage();
mail.From = new MailAddress(fromAddress);
foreach (string recipient in recipientAddress.Split(','))
{
mail.To.Add(new MailAddress(recipient, recipientName));
}
/*
if (msPdf != null)
{
msPdf.Position = 0;
Attachment attachment = new Attachment(msPdf, pdfName, "application/pdf");
mail.Attachments.Add(attachment);
}
*/
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = body;
client.Send(mail);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment