Enable email sending

Source: Internet
Author: User
Tags mailmessage smtpclient

1: namespace used

Using System. Net. Mail;

Using System. Net;

2: Implemented static class

Public static class SendMail

{

/// <Summary>

/// Send an email

/// </Summary>

/// <Param name = "to"> recipient email address </param>

/// <Param name = "from"> sender's email address </param>

/// <Param name = "subject"> subject </param>

/// <Param name = "body"> email content </param>

/// <Param name = "username"> the username used to log on to the smtp host. Note that it is the first part of the email address '@'. </param>

/// <Param name = "password"> User password used to log on to the smtp host </param>

/// <Param name = "smtpHost"> smtp host used for sending emails </param>

Public static void Send (string to, string from, string subject, string body, string userName, string password, string smtpHost)

{

MailAddress from1 = new MailAddress (from );

MailAddress to1 = new MailAddress ();

MailMessage message = new MailMessage (from1, to1 );

Message. Subject = subject; // set the mail Subject

Message. IsBodyHtml = true; // set the email body to html format.

Message. Body = body; // you can specify the email content.

SmtpClient client = new SmtpClient (smtpHost );

// Set the mail Sender authentication method

// Note that if the sender address is a abc@def.com, the user name is abc instead of the abc@def.com

Client. Credentials = new NetworkCredential (userName, password );

Client. Send (message );

}

}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.