Sending email from ASP.Net page using local mail server
Before sending any email you have to create a mailbox.
You will have to use SMTP authentication to send email. The “From” address of the message have to match SMTP authenticated user name. In other words you can only send messages from authenticated mailbox.
Here is a C# code snippet:
///The send from mail address must match SMTP user name.
String smtpUser = "Mailbox@providerdomain.com";
MailMessage msg = new MailMessage(smtpUser, "mail@somedomain.com");
msg.Body = "Some text";
msg.IsBodyHtml = true;
msg.Subject = "Some subject";
SmtpClient SMTP = new SmtpClient("smtp.providerdomain.com", 25);
SMTP.UseDefaultCredentials = false;
SMTP.EnableSsl = false;
SMTP.Credentials = new NetworkCredential()
{
UserName = smtpUser,
Password = "SomePassword"
};
SMTP.Send(msg);