Tuesday, September 22, 2009

How to send email in Asp.net c#



How to send email in Asp.net using c#. In Asp.net 2.0,email sending is very easy.In our websites we send a feedback,contact us,registration welcome,Forgot password, news letter etc. to the users mail.By using the Asp.net classes.
we can access to send the email.The Simple Mail Transfer Protocol(SMTP) server is used for deliver the mail
using the System.Net.Mail namespace.

In System.Net.Mail namespace having two sub classes MailMessage and SmptClient.

MailMessage contains the properties From,To,Subject,Body etc.

SmtpClient send the Mailmessage data to the SMTP server.

The SMTP server Store the emails in a queue.It sends the mail one after another.

The steps to send email:-
1.use the namespace.
using System;
using System.Net.Mail;
using System.Text;

2.use the MailMessage to send the mail with SMTP Connection Settings.
MailMessage mailmsg = new MailMessage("yourfromemail@yourdomain.in", "yourtoemail@domain.com");
SmtpClient smtpmail = new SmtpClient();

mailmsg.Subject = "Account information Verified";
StringBuilder bodyMessage= new StringBuilder();

bodyMessage.Append("<br>");
bodyMessage.AppendFormat("Response From your domain name");
bodyMessage.Append("<br>");
bodyMessage.AppendFormat("Your Account has been deleted if you are not activate\n\n");
bodyMessage.Append("<br>");
bodyMessage.AppendFormat("So Please follow the link To Activate Your Account with Us!\n\n");
bodyMessage.Append("Click Here To Activate Your Account");
bodyMessage.AppendFormat("Registered Email:", "yourtoemail@domain.com");
bodyMessage.AppendFormat("Note:- If U Already Activate your account means Please ignore this message");

mailmsg.Body = bodyMessage.ToString();
smtpmail.Host = "smtp.yourdomain.in";
smtpmail.Port = 587;
smtpmail.Send(mailmsg);

the mail will be send to the to address for activating the account information.

mailmsg.Subject is the subject of our mail.

mailmsg.Body contains the bodymsg string values.it attach the bodymsg with subject.

smtp.Host is your smtp server name for eg.

gmail smtp server is "smtp.gmail.com".

smtpmail.port is the port by sending the mail.

smtpmail.Send function is used to concatenate your message,subject and send the mail through the port with the smtp host address.

Happy to send mail.

45 comments:

  1. great artikel n tutorial

    i will try later

    ReplyDelete
  2. Great...so you're masterring ASP.net ?

    ReplyDelete
  3. Great tutorial thanks for sharing

    We can also submit our .net related links on http://www.dotnettechy.com to increase traffics of your website / blog

    Its kind of social networking for .Net professionals only

    ReplyDelete
  4. Nice weblog right here! Additionally your web site loads up fast!
    What web host are you the use of? Can I get your affiliate hyperlink on your
    host? I want my site loaded up as quickly as
    yours lol

    my site: Free ITunes Gift Card Code Generator, Http://Www.Youtube.Com/,

    ReplyDelete
  5. Nice Articles you have done
    Let me show Solution who face problem to send E-Mail :(5.5.1 authenticaion error in code..)
    http://allittechnologies.blogspot.in/2015/04/the-smtp-server-requires-secure-connection-or-the-client-was-not-authenticated-the-server-response-was-5.5.1-authentication-required.html

    ReplyDelete
  6. his article is very nice and easy to understand, it was a very weighty once thanks a lot admin can hopefully be improved in the future and pardon me permission to share the article here : Cara menyembuhkan gagal jantung

    ReplyDelete
  7. The blog gave me idea to send email in aspnet My sincere thanks for sharing this post and please continue to share this post
    Dot Net Training in Chennai

    ReplyDelete
  8. really you have posted an informative blog. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
    dot net training in chennai

    ReplyDelete
  9. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    digital training in chennai

    ReplyDelete
  10. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
    data-science-training-in-bangalore

    ReplyDelete
  11. Thanks for such a wonder full article. Very good explanation about Asp.Net. Best Cloud Solutins Services | Austere Technologies

    ReplyDelete
  12. Hello we are thanking you beause this blog posts article are wonderfull. massiltechnologies is the best service in world wide mobile application development serivce is NO1 in goble and read more information please visit link Mobile application development Services

    ReplyDelete
  13. Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.

    NO.1 APP DEVELOPMENT SERVICES | MASSIL TECHNOLOGIES

    ReplyDelete
  14. Great information about Asp.net. Thanks for sharing, keep updating.

    Best Mobility Services | Austere Technologies

    ReplyDelete
  15. wow...Great blog about Asp.net, very help full information. Thanks for sharing.

    Best IT Security Services | Austere Technologies

    ReplyDelete
  16. Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.

    Best Commerce College in Hyderabad | Avinash College Of Commerce

    ReplyDelete
  17. Excellent information you made in this blog, very helpful information. Thanks for sharing.

    chartered accountant | Avinash college of commerce

    ReplyDelete
  18. Great article, really very helpful content you made. Thank you, keep sharing.

    Best Degree Colleges Hyderabad | Avinash College of Commerce

    ReplyDelete
  19. Thank you for sharing this valuable information. But get out this busy life and find some peace with a beautiful trip. book ANDAMAN HOLIDAY PACKAGES @ 35999

    ReplyDelete
  20. Hi Thanks for the nice information its very useful to read your blog. We provide best Find All Isfs Courses

    ReplyDelete
  21. Your article gives lots of information to me. Thanks for sharing.
    cima courses in hyderabad | ISFS

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete
  23. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.Learn best Ethical Hacking Training in Bangalore

    ReplyDelete
  24. Thanks for sharing nice information. I highlyrecommend you data science training Hyderabad

    ReplyDelete
  25. Excellent blog!!! I got to know more useful information by reading your blog. Thanks for posting this blog.

    Big Data Training Institute In Bangalore
    Big Data Training In Bangalore

    ReplyDelete
  26. This is my first time i visit here. I found so many entertaining 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 leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea.
    data scientists training

    ReplyDelete
  27. Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing.data science course in warangal

    ReplyDelete
  28. This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses.
    data analytics courses in hyderabad with placements

    ReplyDelete
  29. Really nice information and informative content. I bookmarked your site for further blogs.
    Data Science Courses

    ReplyDelete

Followers