Created
September 17, 2015 15:03
-
-
Save axiak/e2af9ace364362e422a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.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