// Web.Config sample
<configuration>
<system.net>
<mailSettings>
<smtp from="website@website.com">
<network host="mail.website.com" password="" userName=""/>
</smtp>
</mailSettings>
</system.net>
</configuration>
// Code sample
using System.Net.Mail;
MailSettingsSectionGroup mailSettings = WebConfigurationManager.GetSection("system.net/
mailSettings") as MailSettingsSectionGroup;
protected void SendingEmail()
{
// Sending E-Mail
MailMessage message = new MailMessage(mailSettings.Smtp.From, WebConfigurationManager.AppSettings["RecipientList"], "Sending E-mail using web.config", "");
message.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient(mailSettings.Smtp.Network.Host);
smtp.Send(message);
}
No comments:
Post a Comment