Frequently Asked Question

FAQ / Windows Shared Hosting


How to send mail with SMTP authentication in .net C sharp


using System.Net;
using System.Net.Mail;

SmtpClient smtpClient = new SmtpClient();

NetworkCredential basicCredential = new NetworkCredential(username, password);

MailMessage message = new MailMessage();

MailAddress fromAddress = new MailAddress(from@yourdomain-name.com);

smtpClient.Host = your domain-name;

smtp.Port = 25;

smtp.EnableSsl = false;

smtpClient.UseDefaultCredentials = false;

smtpClient.Credentials = basicCredential;

message.From = fromAddress;
message.Subject = your subject;
//Set IsBodyHtml to true means you can send HTML email.
message.IsBodyHtml = true;
message.Body = your message body;
message.To.Add(to@anydomain.com);

try
{
smtpClient.Send(message);
}
catch(Exception ex)
{
//Error, could not send the message
Response.Write(ex.Message);
}

Note :

User name and password is your domain email address and password


For gmail based SMTP authentication :

NetworkCredential basicCredential = new NetworkCredential(yourmail@gmail.com, password);

MailMessage message = new MailMessage();

MailAddress fromAddress = new MailAddress(from@gmail.com);

smtpClient.Host = smtp.gmail.com;

smtp.Port = 587;

smtp.EnableSsl = true;

How this faq is helpful:

Not at all
helpful
Not much
helpful
Some what
helpful
Very
helpful
Extremely
helpful

What could be better? (Optional)
X
  Not related to my issue
  Too complicated explanations
  Too much information
  Incorrect information
  Unclear information
  Incomplete information
  Too old information
Do you have any other feedback about this faq ?
1000