Click here to Skip to main content
15,920,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am not getting to code to project that i want to send mail through ASP .NET + C#... Suppose if i want to send a mail by using my mail id and also by using an office or company host name, how should i code for that.

Jagadish V.
Posted

1 solution

Example:
C# code

using System.Net.Mail;

MailAddress senderMail = new MailAddress("b@b.com", "a");
MailAddress receiverMail = new MailAddress("a@a.com","b");
MailSend(senderMail, receiverMail, "subject hi", "mail html");

private void MailSend(MailAddress sender, MailAddress receiver, string subject, string body)
{
MailMessage message = new MailMessage();
message.From = sender;
message.To.Add(receiver);
message.IsBodyHtml = true;

message.Body = body;
message.Subject = subject;

SmtpClient smtp = new SmtpClient();
try
{
smtp.Send(message);
}
catch (Exception)
{

}
}

in Web.config before <system.web>

<system.net>
<mailSettings>
<smtp>
<network host="127.0.0.1" userName="" password="" port="25"/>
</smtp>
</mailSettings>
</system.net>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900