Email System using ASP.NET 2.0
One of my task last week was to send mass email to customers using web forms. And this was the first time I will create this type of project: The Email System of ASP.NET 2.0. And because of large information around the web, it didn't took me too long hours to finish it, it just need some tweaks. So I want it to publish it under my blog for others to see, and also to learn if there are other way to do this. Take note, I tried to create my own email address, and it works! Wonderful, however, you cannot reply to the email address I've created, it will return a daemon error / failure notice . I wonder this is the way the spammers use to send spams. They will just include their real email address in the body of the message. Cool isn't it?
Under your webconfig file, add additional nodes:
<system.net>
<
mailSettings><smtp><network host="SMTP.BIZMAIL.YAHOO.COM" userName="wdavid@gurango.com" password="******" />
</
smtp></mailSettings>
</
system.net>
<----------Business logic here ---------------------->
//Code starts here, we access the webconfig here
System.Configuration.
Configuration myConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);System.Net.Configuration.MailSettingsSectionGroup mySettings = ((System.Net.Configuration.MailSettingsSectionGroup)myConfig.GetSectionGroup("system.net/mailSettings"));
//Obtain credentials from web.config file under mailsettings node
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential(mySettings.Smtp.Network.UserName, mySettings.Smtp.Network.Password);
//Create an SMTP client here, can be found on account settings in outlookSystem.Net.Mail.SmtpClient myClient = new System.Net.Mail.SmtpClient();
myClient.Host = mySettings.Smtp.Network.Host;
myClient.Credentials = myCredential;
//Build email message here:
//MailMessage myEmail = new MailMessage();System.Net.Mail.MailMessage myEmail=new System.Net.Mail.MailMessage();
myEmail.From =
new System.Net.Mail.MailAddress("willydavidjr@david.com");myEmail.To.Add("willydavidjr@yahoo.com");
myEmail.Subject =
"Test Mail";myEmail.IsBodyHtml = true;
myEmail.DeliveryNotificationOptions = System.Net.Mail.
DeliveryNotificationOptions.OnFailure;myEmail.Body = "<strong>Hello World!</strong>";
myClient.Send(myEmail);
Cool? What do you think guys? Or am I just a newbie here? 