public static void SendViaSendGrid(this MailMessage mailMessage, string sendGridUsername, string sendGridPassword, bool sendAsync) { SmtpClient smtpClient = new SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587)); NetworkCredential credentials = new NetworkCredential(sendGridUsername, sendGridPassword); smtpClient.Credentials = credentials; mailMessage.SendViaSmtp(smtpClient, sendAsync); }