37

Sending Email using ASP.NET

by Mohit Bhardwaj 24. March 2009 02:01

Last night I was thinking to write a small post about sending emails using .NET. Then I thought of using GMAIL smtp account to send email. So here is the code.

using System;
using System.Net;
using System.Net.Mail;

/// <summary>
/// Email Sending Class for GMAIL account.
/// </summary>

public class Emails
{
public Emails()
{
//
// TODO: Add constructor logic here
//
}

 

public string sendmail(string body)
{
try
{
MailMessage mail=
new MailMessage();
mail.To.Add(new MailAddress("xxxx@gmail.com"));
mail.From=
new MailAddress("yyyy@gmail.com");
mail.Body=body;
SmtpClient smtp=
new SmtpClient("smtp.gmail.com",587);
smtp.Credentials=new NetworkCredential("yyyy@gmail.com", "#&&$$%#%"); // This is where you have to specify account properties of the email account you are using to send email. yyyy@gmail.com is the userid and #&&$$%#% is the password.
smtp.EnableSsl=true;
smtp.Send(mail);
return "Success";
}
catch(Exception ex)
{
return "Failed";
}
}
 

Now from here you can call this class and send email. I have used the static emails here but you can make it change accordingly to use it as dynamically. You will need to add more paramaters like "body" in calling this function.

Thanks.

Tags:

Beginners

Comments

Bree Piselli
Bree Piselli United States
2/8/2012 1:04:12 PM #

Hello.This post was really remarkable, particularly because I was searching for thoughts on this topic last Monday.

Jeanelle Valaitis
Jeanelle Valaitis United States
2/8/2012 1:07:34 PM #

Aw, this was a really nice post. In thought I would like to put in writing like this additionally – taking time and precise effort to make a very good article… however what can I say… I procrastinate alot and not at all appear to get one thing done.

Fotele obrotowe
Fotele obrotowe United States
2/8/2012 1:41:12 PM #

I like this blog  so much,  saved to favorites .

Gucci Belts
Gucci Belts United States
2/8/2012 1:47:51 PM #

Although it has become a little out-of-date script, but it actually compensated for my time. I am going to post a link to this page on my web page. I am sure my visitors may find that very helpful.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 1:57:41 PM #

An fascinating communication is worth interpret. I consider that you should write many on this substance, it might not be a preconception thing but mostly fill are not sufficiency to talk on much topics. To the next. Cheers like your Developer's Mind | Sending Email using ASP.NET.

Belly Button Rings
Belly Button Rings United States
2/8/2012 1:57:46 PM #

An exciting discourse is designer note. I imagine that you should create writer on this matter, it strength not be a preconception subject but mostly group are not sufficiency to verbalize on such topics. To the succeeding. Cheers like your Developer's Mind | Sending Email using ASP.NET.

Knock Knock Jokes
Knock Knock Jokes United States
2/8/2012 1:57:52 PM #

An intriguing communication is designer scuttlebutt. I cogitate that you should create many on this issue, it power not be a preconception subject but mostly group are not enough to mouth on much topics. To the succeeding. Cheers like your Developer's Mind | Sending Email using ASP.NET.

Knock Knock Jokes
Knock Knock Jokes United States
2/8/2012 2:11:54 PM #

I'm not sure where you're getting your information, but good topic. I needs to spend some time learning much more or understanding more. Thanks for excellent info I was looking for this Developer's Mind | Sending Email using ASP.NET for my mission.

Belly Button Rings
Belly Button Rings United States
2/8/2012 2:11:56 PM #

I am not sure where you're getting your info, but great topic. I needs to spend some time learning much more or understanding more. Thanks for fantastic information I was looking for this Developer's Mind | Sending Email using ASP.NET for my mission.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 2:11:59 PM #

I am not sure where you are getting your info, but good topic. I needs to spend some time learning more or understanding more. Thanks for excellent information I was looking for this Developer's Mind | Sending Email using ASP.NET for my mission.

 best iphone apps download
best iphone apps download United States
2/8/2012 2:18:08 PM #

Im no pro, but I think you just made a very good point point. You clearly comprehend what youre speaking about, and I can actually get behind that. Thanks for staying so upfront and so honest.

Yahoo Answer Services
Yahoo Answer Services United States
2/8/2012 2:21:38 PM #

I¡¦ll right away grab your rss feed as I can't find your email subscription hyperlink or e-newsletter service. Do you've any? Kindly permit me know in order that I may just subscribe. Thanks.


I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

Knock Knock Jokes
Knock Knock Jokes United States
2/8/2012 2:31:55 PM #

An unputdownable treatment is worth comment. I think that you should create much on this theme, it might not be a bias substance but mostly fill are not enough to mouth on much topics. To the next. Cheers like your Developer's Mind | Sending Email using ASP.NET.

Belly Button Rings
Belly Button Rings United States
2/8/2012 2:31:57 PM #

An engrossing language is couturier observe. I reckon that you should create author on this message, it might not be a prejudice subordinate but generally people are not enough to communicate on much topics. To the next. Cheers like your Developer's Mind | Sending Email using ASP.NET.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 2:31:59 PM #

An unputdownable discourse is couturier observe. I reckon that you should make statesman on this matter, it might not be a bias matter but generally group are not sufficiency to talk on such topics. To the next. Cheers like your Developer's Mind | Sending Email using ASP.NET.

vancouver webdesign
vancouver webdesign United States
2/8/2012 2:41:10 PM #

Of course, what a splendid site and enlightening posts, I surely will bookmark your blog.All the Best!

krzesła do jadalni
krzesła do jadalni United States
2/8/2012 2:41:18 PM #

Thanks for sharing your ideas on this blog. Also, a myth regarding the financial institutions intentions any time talking about property foreclosure is that the bank will not getreceive my installments. There is a fair bit of time which the bank is going to take payments here and there. If you are way too deep within the hole, they will commonly desire that you pay the particular payment entirely. However, i am not saying that they will have any sort of installments at all. If you and the traditional bank can manage to work anything out, a foreclosure procedure may cease. However, if you continue to miss payments under the new program, the foreclosures process can just pick up where it was left off.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 2:49:55 PM #

I'm not sure where you are getting your information, but great topic. I needs to spend some time learning much more or understanding more. Thanks for fantastic information I was looking for this Developer's Mind | Sending Email using ASP.NET for my mission.

Belly Button Rings
Belly Button Rings United States
2/8/2012 2:49:59 PM #

I am not sure where you're getting your information, but good topic. I needs to spend some time learning much more or understanding more. Thanks for magnificent information I was looking for this Developer's Mind | Sending Email using ASP.NET for my mission.

Knock Knock Jokes
Knock Knock Jokes United States
2/8/2012 2:50:03 PM #

I'm not sure where you're getting your information, but good topic. I needs to spend some time learning more or understanding more. Thanks for magnificent info I was looking for this Developer's Mind | Sending Email using ASP.NET for my mission.

Roxana Deboard
Roxana Deboard United States
2/8/2012 2:51:34 PM #

    

Belly Button Rings
Belly Button Rings United States
2/8/2012 2:52:41 PM #

I am not sure where you're getting your information, but good topic. I needs to spend some time learning much more or understanding more. Thanks for wonderful information I was looking for this Developer's Mind | Sending Email using ASP.NET for my mission.

Knock Knock Jokes
Knock Knock Jokes United States
2/8/2012 2:52:42 PM #

I'm not sure where you are getting your information, but great topic. I needs to spend some time learning more or understanding more. Thanks for wonderful info I was looking for this Developer's Mind | Sending Email using ASP.NET for my mission.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 2:52:42 PM #

I am not sure where you're getting your info, but great topic. I needs to spend some time learning much more or understanding more. Thanks for magnificent information I was looking for this Developer's Mind | Sending Email using ASP.NET for my mission.

Pete Gennaro
Pete Gennaro United States
2/8/2012 3:06:01 PM #

I am not sure where you're getting your <a href="www.philadelphiaflyersjerseysshop.com/chris-pronger-jerseys-c-5.html">Chris Pronger Jersey</a> information, but good topic. I needs to spend some time learning much more or understanding more. Thanks for magnificent information I was looking for this <a href="www.philadelphiaflyersjerseysshop.com/claude-giroux-jerseys-c-6.html">Claude Giroux Jersey</a> info for my mission.

Milford Stancil
Milford Stancil United States
2/8/2012 3:17:22 PM #

The following time I learn a weblog, I hope that it doesnt disappoint me as a lot as this one. I imply, I do know it was my option to learn, however I truly thought youd have something interesting to say. All I hear is a bunch of whining about one thing that you could fix in the event you werent too busy searching for attention.

Shop Shoes
Shop Shoes United States
2/8/2012 3:22:47 PM #

Enjoyed  reading through  this, very good stuff,  regards . "Nothing happens to any thing which that thing is not made by nature to bear." by Marcus Aurelius Antoninus.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 3:27:16 PM #

Great goods from you, man. Developer's Mind | Sending Email using ASP.NET I have understand your stuff previous to and you're just too wonderful. I really like what you've acquired here, certainly like what you are saying and the way in which you say it. You make it entertaining and you still care for to keep it sensible. I can't wait to read much more from you. This is actually a wonderful Developer's Mind | Sending Email using ASP.NET informations.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 3:29:42 PM #

Great goods from you, man. Developer's Mind | Sending Email using ASP.NET I've understand your stuff previous to and you are just too excellent. I actually like what you've acquired here, certainly like what you're stating and the way in which you say it. You make it enjoyable and you still care for to keep it sensible. I can not wait to read much more from you. This is actually a wonderful Developer's Mind | Sending Email using ASP.NET informations.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 3:43:53 PM #

Great goods from you, man. Developer's Mind | Sending Email using ASP.NET I've understand your stuff previous to and you are just too wonderful. I actually like what you've acquired here, really like what you are saying and the way in which you say it. You make it entertaining and you still care for to keep it sensible. I can not wait to read far more from you. This is really a terrific Developer's Mind | Sending Email using ASP.NET informations.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 3:43:54 PM #

Excellent goods from you, man. Developer's Mind | Sending Email using ASP.NET I have understand your stuff previous to and you are just too wonderful. I actually like what you've acquired here, really like what you're saying and the way in which you say it. You make it enjoyable and you still care for to keep it wise. I can not wait to read much more from you. This is really a wonderful Developer's Mind | Sending Email using ASP.NET informations.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 3:43:56 PM #

Excellent goods from you, man. Developer's Mind | Sending Email using ASP.NET I've understand your stuff previous to and you're just too fantastic. I actually like what you have acquired here, really like what you're saying and the way in which you say it. You make it enjoyable and you still take care of to keep it smart. I can not wait to read much more from you. This is really a great Developer's Mind | Sending Email using ASP.NET informations.

Naturally Weight Lose
Naturally Weight Lose United States
2/8/2012 3:46:41 PM #

Magnificent goods from you, man. Developer's Mind | Sending Email using ASP.NET I have understand your stuff previous to and you are just extremely excellent. I actually like what you have acquired here, certainly like what you're stating and the way in which you say it. You make it enjoyable and you still take care of to keep it smart. I can not wait to read much more from you. This is actually a tremendous Developer's Mind | Sending Email using ASP.NET informations.

gazebos and pergolas
gazebos and pergolas United States
2/8/2012 4:04:37 PM #

Like a web-site owner I do believe this great article (reject) here is   extraordinary , My partner and i appreciate your projects.It is advisable to stay the best a long time! All the best .

free dating site
free dating site United States
2/8/2012 4:40:08 PM #

Even though this view is common in today's world, it is still something that needs to be remembered. It was a superb read.

Elvin Oelschlager
Elvin Oelschlager United States
2/8/2012 5:06:38 PM #

Thanks , I have just been looking for information approximately this topic for a long time and yours is the greatest I have discovered till now. But, what concerning the conclusion? Are you positive about the source?

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.0.0
Original Design by Laptop Geek, Adapted by onesoft