To start page

Sending email from EPiServer

public static void SendEmail(string subject, string message, 
string from, string to, bool isHtml) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(from); mail.To.Add(to); mail.Subject = subject; mail.Body = message; mail.IsBodyHtml = isHtml; SmtpClient smtp = GetConfiguredSmtpClient(); smtp.Send(mail); }

GetConfiguredSmtpClient below comes from the EPiServer sample templates.

public static SmtpClient GetConfiguredSmtpClient(string smtpServer, 
int smtpPort, string userName, string password) { SmtpClient smtp = new SmtpClient(); // Setup the host and port const int DefaultSmtpPort = 25; if (smtpPort == -1) smtpPort = (int)EPiServer.Global.EPConfig["EPnSmtpServerPort"]; if (smtpPort < 1 || smtpPort > 65535) smtpPort = DefaultSmtpPort; if (smtpPort != DefaultSmtpPort) { smtp.Port = smtpPort; } if (smtpServer == null) smtpServer = (string)EPiServer.Global.EPConfig["EPsSmtpServer"]; if (smtpServer.Length > 0) { smtp.Host = smtpServer; } // Setup the smtp authentication if (userName == null) userName = (string)EPiServer.Global.EPConfig["EPsSmtpUser"]; if (password == null) password = (string)EPiServer.Global.EPConfig["EPsSmtpPassword"]; // User/password may both be empty -- in that case just ignore everything... if (userName.Length != 0 || password.Length != 0) { // If one has been defined, the other must also be defined if (userName.Length == 0) throw new EPiServerException("Undefined username"); if (password.Length == 0) throw new EPiServerException("Undefined password"); smtp.Credentials = new NetworkCredential(userName, password); } return smtp; }
Comment this page
(No of comments: 0)

All rights reserved © 2007 epiforum.net | All trademarks and registered trademarks appearing on epiforum.net are the property of their respective owners. Every effort is made to provide accurate & complete information. However we cannot guarantee that there will be no errors and we do not make any warranty, expressed or implied, including the warranties of merchantability and fitness for a particular purpose with respect to documents available from epiforum.net. Additionally, epiforum.net assume no legal liability for the accuracy, completeness, or usefulness of any information, product, or process disclosed herein and do not represent that use of such information, product, or process would not infringe on privately owned rights. epiforum.net a brainchild of INEXOR AB.