Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Please help me to configure SMTP server pointing to local SMTP server, my main server somewhare.(Ex google,yahoo,etc..)


Masseage sender from outlook ----> Local SMTP ---> clinet network( limited access )----> My SMTP server ( third party hosters)--> mail Receiver.

Thanks in Advance.
Srinivas G
Posted

1 solution

To send emails, use VS 2010 SMTP. You define related parameters in the .config as follows:


<pre><system.net>
  <mailSettings>
    <smtp from="youremail@yourdomain.com">
      <network host="mail.yourdomain.com" port="yourport" userName="youremail@yourdomain.com" password="yourpassword" defaultCredentials="false"/>
    </smtp>
  </mailSettings>
</system.net>



As an example of the C# code to send emails:

public static void Send(string Subject, string From, string Body, List<emailAddress> CC, MailAddress To, bool BodyHTML)
{
  try
  {
    MailMessage mail = new MailMessage();
    if (CC != null)
    {
      foreach (emailAddress ea in CC)
      {
        mail.CC.Add(new MailAddress(ea.email, ea.fullname));
      }
    }
    mail.Subject = Subject;
    mail.Body = Body;
    mail.IsBodyHtml = BodyHTML;
    mail.From = new MailAddress(From);
    mail.To.Add(To);

    SmtpClient client = new SmtpClient();
    client.Host = "mail.yourdomain.com";
    client.Send(mail);
  }
  catch (Exception ex)
  {
    throw new Exception(ex.Message);
  }
}
 
Share this answer
 
v2

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