-2

Possible Duplicate:
Sending email in .NET through Gmail

I don't know what is the apis needed to send emails using gmail and hotmail using .Net , if someone know it will be very useful for me also how to install those libraries into VS 2010

2 답변


6

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

<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);
  }
}


  • I understand now so I need to make the server as gmail server and send the email ?? - Ahmed Kato
  • I have only used private domain's SMTP servers to send emails, but I guess you can try using mail.gmail.com as the host and specify your own email address and password. - ron tornambe

0

You're looking for the System.Net.Mail namespace. No external libraries needed - to start just add a using directive to it at the top of your class.

Here's a site with some good references to get you started: http://www.systemnetmail.com/


Linked


Related

Latest