public void SendMaiL(string sSubject, string[] arToAddress, string[] arToAddressCC, int? iReqEmpId, int iMailType) { string sBody = string.Empty; bool enableSSL = true; if (arToAddress != null && arToAddress.Length > 0) { try { string sServer = "smtp.mail.com"; int iPort =587; string sUserName = ConfigurationManager.AppSettings["userName"].ToString(); string sPassword = ConfigurationManager.AppSettings["password"].ToString(); string sFrom = ConfigurationManager.AppSettings["from"].ToString(); //oSmtpClient.UseDefaultCredentials = false; //oSmtpClient.Credentials = new NetworkCredential(sUserName, sPassword); MailMessage oMailMessage = new MailMessage(); ; oMailMessage.From = new MailAddress(sFrom); if (arToAddress != null && arToAddress.Length > 0) { sBody = GetMailBody(Convert.ToInt32(arToAddress[0]), iMailType, iReqEmpId); for (int t = 0; t <= arToAddress.Length - 1; t++) { oMailMessage.To.Add(new MailAddress(GetEmpMailId(Convert.ToInt32(arToAddress[t].ToString())))); } } if (arToAddressCC != null && arToAddressCC.Length > 0) { for (int i = 0; i <= arToAddressCC.Length - 1; i++) { if (arToAddressCC[i] != null) oMailMessage.CC.Add(new MailAddress(GetEmpMailId(Convert.ToInt32(arToAddressCC[i].ToString())))); } } oMailMessage.Subject = sSubject; oMailMessage.Body = sBody; oMailMessage.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient(sServer, iPort)) { smtp.Credentials = new NetworkCredential(sFrom, sPassword); smtp.EnableSsl = enableSSL; smtp.Send(oMailMessage); } } catch (Exception ex) { //WriteLog(ex.ToString()); } } }
string sServer = "smtp.mail.com";
string sServer = "smtp.gmail.com";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)