Programming is Passion,Software Development is an Adventure- Willy David Jr

Programming is Passion,Software Development is an Adventure- Willy David Jr

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 outlook

System.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? Stick out tongue

 

Comments

jop said:

"I wonder this is the way the spammers use to send spams" -- That's exactly how spammers do it. Most SMTP servers do not check if the "From" address comes from a valid account. But be careful when sending mass mails using yahoo or any server that you do not own. The system admins might detect your activities, think that you are sending out spam and then block your IP or your company's IP. Better test that using your own SMTP servers.

# November 20, 2007 9:45 PM

lamia said:

I did this before with PHP and my mails always ended up on the bulk folder. -_-

I think it has something to do with Mail Exchanger(MX)?

# November 21, 2007 6:52 AM

keithrull said:

hehehe, i have a small application that dos this. Basically i have a web app that allows users to design their email and attachment to it then once the user clicks the send button the message would be saved into the database. A second application(windows service) would then pick up the message and send it to the necessary receipcients(bulk, usually 1000 or more). btw, this app is not for spam, its for a marketing campaign on one of my clients.

# November 21, 2007 1:37 PM

willydavidjr said:

@lamia

I don't know but I approved your post already but I cannot see it here, anyway, all of my "mock up" emails didn't end up on bulk folder. I think it depends on the recipient's server

@keithrull

I'll try that one too (that windows service)..

# November 21, 2007 4:46 PM

cruizer said:

different service providers/networks have different heuristics in "determining" a spammer. some would block out servers whose reverse DNS entry (from IP to name) does not match the mail domain name. some have a blacklist of sorts. some routinely pass random message samples and see if they match typical spam, and if the percentage of spam messages is high, they put the server on a blacklist.

# November 23, 2007 2:18 AM

Rannajee said:

Actually i go through all these comment but i like know or develop the system that receive mail and store in the file system or database

# January 10, 2008 3:10 AM

rocky said:

dude......how abt receiving emails and putting it into the database.....

# April 8, 2008 7:21 AM

Memmorium said:

     Good idea!

P.S. A U realy girl?

# April 11, 2008 7:22 AM

KIRTI said:

SENDIMG MAIL APPLICATION WITH ATTCHEMENT BY SMTP MAILM SERVER IN ASP.NET 2.0

ITS GIVE FAILUR MAIL SEND

# April 22, 2008 5:41 AM

willydavidjr said:

Maybe your network host and username are incorrect.

# April 29, 2008 6:20 PM

Вечерний макияж глаз фото said:

I not understend what U want

# May 15, 2008 12:48 AM

willydavidjr said:

I mean double check your credential in web.config file. And one thing, I haven't tested this if you have an attachment.

# May 18, 2008 8:11 AM

Das said:

Somehow i am getting the error "Mailbox unavailable. The server response was: 5.7.1 Unable to relay for <the email to which i was sending>". The following line is highlighted:

myClient.Send(myEmail);

any ideas wat the problem could be?

# June 7, 2008 8:01 AM

Affordable Web Design Ireland said:

Excellent article - I've been looking for it! Thanks

# June 9, 2008 3:19 AM