SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); MailAddress fromAddress = new MailAddress(fromMail, ""); // You can specify the host name or ipaddress of your server // Default in IIS will be localhost smtpClient.Host = ConfigurationManager.AppSettings["SMTPServer"]; smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; string SMTPAuthenticationFlag = ConfigurationManager.AppSettings["SMTPAuthenticationFlag"] != null ? Convert.ToString(ConfigurationManager.AppSettings["SMTPAuthenticationFlag"].ToString()) : "0"; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SMTPUserName"], ConfigurationManager.AppSettings["SMTPPassword"]); int SMTPServerPort = 587; smtpClient.Port = SMTPServerPort; //Added by Alex on 20240625 for sending mail with TLS (Mantis Id-1859) Start string SMTPServerSSLFlag = ConfigurationManager.AppSettings["SMTPServerSSLFlag"] != null ? Convert.ToString(ConfigurationManager.AppSettings["SMTPServerSSLFlag"].ToString()) : "0"; if (SMTPServerSSLFlag == "1") { smtpClient.EnableSsl = true; } //Added by Alex on 20240625 for sending mail with TLS (Mantis Id-1859) End //From address will be given as a MailAddress Object message.From = fromAddress; // To address collection of MailAddress message.To.Add(toMail); message.Subject = subject; message.IsBodyHtml = true; // Message body content message.Body = mailContent; // Send SMTP mail smtpClient.Send(message);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)