I'm new to ASP.NET with C#. Can anybody guide me on how to send an email through ASP.NET with C# using server (including configuring the server).
1 Answer
using System.Net.Mail;
...
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.To.Add(new MailAddress("[email protected]"));
message.To.Add(new MailAddress("[email protected]"));
message.CC.Add(new MailAddress("[email protected]"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);
in the web.config
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
</smtp>
</mailSettings>
Thanks Scott
3 Comments
Sri
hai thanx for your reply... can you please explain what is host-"smtpserver1" username="username" password="secret".... where i going to get all these...????
Paul Creasey
Google it, your can set up your own, use ur ISP's, use google/yahoo mails smtp servers.
Sri
hai paul thanx the mail send successfully but i use localhost for sending the mail. could you tell me where the mail is store in my mail???????