ASP.NET


How can I send a mail from .NET using SMTP Authentication ?
VB Code

Dim msg As New MailMessage("to@example.com", "<emailaddress in your domain>")
msg.Subject = "Subject here"
msg.Body = "Body here"

Dim client As New SmtpClient("localhost")
client.Credentials = New Net.NetworkCredential("<email address in your domain>", "<password of this emailaccount>")
client.Send(msg)


C# Code

System.Net.Mail.MailMessage eMail = new System.Net.Mail.MailMessage();
eMail.IsBodyHtml = true;
eMail.Body = body;
eMail.From = new System.Net.Mail.MailAddress(fromEmail);
eMail.To.Add(toEmail);
eMail.Subject = subject;
System.Net.Mail.SmtpClient SMTP = new System.Net.Mail.SmtpClient();

SMTP.Credentials = new System.Net.NetworkCredential("user","pass");
SMTP.Host = "localhost";
SMTP.Send(eMail);
Tips:
It is only localhost if the application is sitting on the same server as the IMAP service. If you are connecting externally you would need mail.domain.com .

You would replace localhost with the SMTP server for gmail. Email address and password would be your gmail credentials.