C # Send mail

Source: Internet
Author: User
Tags mailmessage smtpclient

You want to use QQ mail to send mail to configure the mail server for the QQ mailbox mail server mail.qq.com.
Then fromaddress there to configure your email address,
Objsmtpclient.credentials need your email and password.
Method SendMail (String mailaddress, String mailtitle, String mailcontent)
Need parameters mailaddress for the email address you want to send, mailtitle for the message subject, mailcontent for the message content.
Reference is also required: using System.Net.Mail;

public static void SendMail (String mailaddress, String mailtitle, String mailcontent)
{
MailMessage objmailmessage = new MailMessage ();
String fromaddress = configurationmanager.appsettings["fromaddress"];//the sender address that you configured in Web. config is your e-mail address.
String mailHost = configurationmanager.appsettings["MailHost"];//mail server, such as mail.qq.com

Objmailmessage.from = new MailAddress (fromaddress);//Sender Address
OBJMAILMESSAGE.TO.ADD (New MailAddress (mailaddress));//Addressee Address
objmailmessage.bodyencoding = system.text.encoding.utf8;//message encoding
Objmailmessage.subject = mailtitle;//message Header
Objmailmessage.body = mailcontent;//message content
objmailmessage.isbodyhtml = true;//Whether the message body is in HTML format

SmtpClient objsmtpclient = new SmtpClient ();
Objsmtpclient.host = mailhost;//mail server address
Objsmtpclient.deliverymethod = smtpdeliverymethod.network;//sent over the network to the STMP mail server
Objsmtpclient.credentials = new System.Net.NetworkCredential ();//sender's email address, password
OBJSMTPCLIENT.ENABLESSL = TRUE;//SMTP server requires a secure connection to set this property

Try
{
Objsmtpclient.send (Objmailmessage);
}
catch (Exception ex)
{
Loghelper.writelog (Logfile.error, ex. ToString ());//Record error log
}
}

C # Send mail

Related Article

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.