Home | Index | Dotnet4all Snippets | Submit resources
About | Mail us 
How to Send an email using SMTP (C#) (16 April 2007)


 
Sending Email is easy. The only conditions is that you have to have access to an SMTP mailing service.
  using System.Web.Mail;

  ...

  public static void SendF4Mail(string in_Body, string in_Subject, _
                              string in_From, string in_To, string in_Bcc)
  {
    MailMessage lv_Mail = new MailMessage();
    string lv_MySMTPServer = "smtp.xxxxx.xxxx";  //Your SMTP server

    lv_Mail.To = in_To;  //Valid Emailadres
    lv_Mail.Bcc = in_Bcc;  //Valid Emailadres
    lv_Mail.Subject = in_Subject;
    lv_Mail.From = in_From;  //Valid Emailadres (that is allowed to relay).
    lv_Mail.Body = in_Body;
    lv_Mail.Priority = MailPriority.Normal;
    lv_Mail.BodyFormat = MailFormat.Html;  //or MailFormat.Text
    SmtpMail.SmtpServer.Insert(0,lv_MySMTPServer);
    SmtpMail.Send(lv_Mail);  //Send the email
  }

Posted by Xander Zelders



0 Comments:

Post a Comment

<< Home

 
Previous Posts
    - How to remove HTML-tags from web content (C#)
    - How to convert DateTime to SQL valid string



Disclaimer & Terms of Use | DotNet4All.Com concept & © 2004 - 2007 by Zelders² - Holland