Skip to content

Instantly share code, notes, and snippets.

@axiak
Created Sep 17, 2015
Embed
What would you like to do?
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