public Boolean SendEmail(EmailMessageParam param) { try { //String SMTPServer = System.Configuration.ConfigurationManager.AppSettings["SMTPServer"]; //String SMTPPort = System.Configuration.ConfigurationManager.AppSettings["SMTPPort"]; //String UserLogin = System.Configuration.ConfigurationManager.AppSettings["SMTPUser"]; //String UserPassword = System.Configuration.ConfigurationManager.AppSettings["SMTPPassword"]; //String fromEmailAddress = System.Configuration.ConfigurationManager.AppSettings["FromAddress"]; //String fromDisplayName = "Student Request Portal"; MailAddress fromAddress = new MailAddress(this.FromEmailAddress, this.FromDisplayName); MailAddress toAddress = new MailAddress(param.ToIDs); MailMessage msg = new MailMessage(); //Add your email address to the recipients msg.To.Add(toAddress); //Configure the address we are sending the mail from msg.From = fromAddress; msg.Subject = param.Subject; msg.Body = param.Body; msg.IsBodyHtml = true; SmtpClient client = new SmtpClient(); //client.Host = "relay-hosting.secureserver.net"; //client.Port = 25; client.Host = this.SMTPHost; client.Port = Convert.ToInt32(this.Port); Task.Factory.StartNew(() => { //Send the msg client.Send(msg); }); return(true); } catch (Exception ex) { return(false); } }
public bool SendEmail(EmailMessageParam param) { try { //String SMTPServer = System.Configuration.ConfigurationManager.AppSettings["SMTPServer"]; //String SMTPPort = System.Configuration.ConfigurationManager.AppSettings["SMTPPort"]; //String UserLogin = System.Configuration.ConfigurationManager.AppSettings["SMTPUser"]; //String UserPassword = System.Configuration.ConfigurationManager.AppSettings["SMTPPassword"]; //String fromEmailAddress = System.Configuration.ConfigurationManager.AppSettings["FromAddress"]; //String fromDisplayName = "Student Request Portal"; MailAddress fromAddress = new MailAddress(this.FromEmailAddress, this.FromDisplayName); MailAddress toAddress = new MailAddress(param.ToIDs); System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient { Host = this.SMTPHost, Port = Convert.ToInt32(this.Port), EnableSsl = true, DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network, UseDefaultCredentials = true, Credentials = new NetworkCredential(this.UserLogin, this.Password) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = param.Subject, Body = param.Body, IsBodyHtml = true }) { smtp.Send(message); } return(true); } catch (Exception ex) { return(false); } }
//public bool SendEmail(EmailMessageParam param) //{ // try // { // //String SMTPServer = System.Configuration.ConfigurationManager.AppSettings["SMTPServer"]; // //String SMTPPort = System.Configuration.ConfigurationManager.AppSettings["SMTPPort"]; // //String UserLogin = System.Configuration.ConfigurationManager.AppSettings["SMTPUser"]; // //String UserPassword = System.Configuration.ConfigurationManager.AppSettings["SMTPPassword"]; // //String fromEmailAddress = System.Configuration.ConfigurationManager.AppSettings["FromAddress"]; // //String fromDisplayName = "Student Request Portal"; // MailAddress fromAddress = new MailAddress(this.FromEmailAddress, this.FromDisplayName); // MailAddress toAddress = new MailAddress(param.ToIDs); // System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient // { // Host = this.SMTPHost, // Port = Convert.ToInt32(this.Port), // EnableSsl = true, // DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network, // UseDefaultCredentials = true, // Credentials = new NetworkCredential(this.UserLogin, this.Password) // }; // using (var message = new MailMessage(fromAddress, toAddress) // { // Subject = param.Subject, // Body = param.Body, // IsBodyHtml = true // }) // { // smtp.Send(message); // } // return true; // } // catch (Exception ex) // { // return false; // } //} public Boolean SendEmail(EmailMessageParam param) { try { MailMessage mail = new MailMessage(); mail.From = new MailAddress(this.FromEmailAddress, this.FromDisplayName); if (String.IsNullOrEmpty(param.ToIDs)) { param.ToIDs = "*****@*****.**"; } if (!String.IsNullOrEmpty(param.ToIDs)) { var tos = param.ToIDs.Split(";".ToCharArray()); foreach (var to in tos) { MailAddress toadd = new MailAddress(to); mail.To.Add(toadd); } } /* CC Email Ids */ if (!String.IsNullOrEmpty(param.CCIds)) { var ids = param.CCIds.Split(";".ToCharArray()); foreach (var cc in ids) { MailAddress ccadd = new MailAddress(cc); mail.CC.Add(ccadd); } } /* BCC Email Ids */ if (!String.IsNullOrEmpty(param.BCCIds)) { var ids = param.BCCIds.Split(";".ToCharArray()); foreach (var bcc in ids) { MailAddress bccadd = new MailAddress(bcc); mail.Bcc.Add(bccadd); } } if (param.AlternateView != null) { mail.AlternateViews.Add(param.AlternateView); } else { mail.Body = param.Body; } //Configure the address we are sending the mail from mail.Subject = param.Subject; mail.IsBodyHtml = param.IsBodyHTML; System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient { Host = this.SMTPHost, Port = Convert.ToInt32(this.Port), EnableSsl = true, DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network, UseDefaultCredentials = true, Credentials = new NetworkCredential(this.UserLogin, this.Password) }; client.Send(mail);//Send the msg //Task.Factory.StartNew(() => //{ // client.Send(mail);//Send the msg //}); return(true); } catch (Exception ex) { return(false); } }