Sending Mail through ASP.NET c#


Sending Mail through ASP.NET c# by using this code of lines

//this code is help to sending emails through ASP.NET c#
// and directly send into inbox not in spam
//Go through some steps

first Step


write code in web.config file



<system.net>
< mailSettings >
<smtp from="sender Name">
<network host="mail.Gmail.com" password="Email ID password" userName="sender Email ID" />
</smtp>
</mailSettings>
</system.net>




Second Step



//use Necessary library
using System.Web.Mail;

third Step



//function to sending mail
//here create a (smtp) object

public void semdMail()
{
//create mail object
MailMessage mail = new MailMessage();
// mail parameters
mail.To = "Receiver EmailID";
mail.From = "Sender Email ID";
mail.Subject = "Subject";
mail.Body = "Message";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(mail);
}


Related Articles

SilverPop Integration

SilverPop is a third party emailing tool which is not only provide the facility to prepare the email templates which needs to be used in sending an email as well as it provides the support for campaign management through various things.

More articles: Email using ASP.NET Sending mail through c# Email

Comments

Author: Devendra Singh Rathore05 May 2010 Member Level: Silver   Points : 1

Nice Snippets send mails successfully ....

but when i Test this code in my website all mails are received in Spam folder

only want to do is to send mails that will show in the inbox folder in receiver mails.

Thanks in advance.............

Author: shubhang sahai mathur05 May 2010 Member Level: Silver   Points : 1

hi,

thank for respond me

you can not go through first step

read the step 1 carefully and apply inside your web.config file

You will defiantly receive your message in inbox

Author: john14 Jun 2010 Member Level: Bronze   Points : 2

Pro: Upgrading Your Enterprise Support (70-621) 70-680 certification exam is the one, if the need to obtain a MCTS certification, you may also need to attend other relevant examinations,000-431 Certification. 70-663 certification is the certification authority, one has a pivotal position in the international. If you have a 000-649 certification, you enter the IT industry coupled with the power company will a heavy weight. The certificate holders will enjoy worldwide free credit 000-816 relevant professional treatment, some countries in North America as immigrants technical evaluation criteria. Vrf Obtain any level of 70-662 certification means you are one of influential figure IT industry.

Author: shankar20 Jul 2010 Member Level: Gold   Points : 1

if we are declaring sender details in web.config in advance then how can i pass the fields dynamically and i hope the above code will work for same sender email id and if we want dynamically sender addresses then what to do

Author: Pal (Parthiv) Patel26 Jul 2010 Member Level: Gold   Points : 1

hey how you do this man??

i will try it for a lot but it cant possible.


its too good.

thank you so much

hey how you do this man??

i will try it for a lot but it cant possible.

Author: Rajkumar Pomaji27 Jul 2010 Member Level: Gold   Points : 1

Hey nice one article ,


Keep it up

Thanks and Regards
Rajkumar Pomaji

Author: Er. Ram Singh06 Sep 2010 Member Level: Gold   Points : 2

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Net.Mail;public partial class Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) {//Calling the function SendMail Response.Write( SendMail("meetuchoudhary@gmail.com","meetudmeet@gmail.com","meetudmeet@yahoo.com","Test Mail","Test Mail Body")); } public string SendMail(string toList, string from, string ccList, string subject, string body) { MailMessage message = new MailMessage(); SmtpClient smtpClient = new SmtpClient(); string msg = string.Empty; try { MailAddress fromAddress = new MailAddress(from); message.From = fromAddress; message.To.Add(toList); if (ccList != null && ccList != string.Empty) message.CC.Add(ccList); message.Subject = subject; message.IsBodyHtml = true; message.Body = body; smtpClient.Host = "mail.server.com"; smtpClient.Port = 25; smtpClient.UseDefaultCredentials = true; smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com", "password"); smtpClient.Send(message); msg = "Successful"; } catch (Exception ex) { msg = ex.Message; } return msg; }}

Author: stevemartyn01 Oct 2010 Member Level: Bronze   Points : 1

if we are declaring sender details in web.config in advance then how can i pass the fields dynamically and i hope the above code will work for same sender email id and if we want dynamically sender addresses then what to do 70-515



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: