Using. NET code to send mail _ practical tips

Source: Internet
Author: User
Tags mailmessage net send smtpclient

The example of this article for everyone to share the implementation code of the. Net send mail, for everyone's reference, the specific contents are as follows

Key code:

Need to reference namespaces:

Using System.Net.Mail;
Using System.Net;

MailMessage mailobj = new MailMessage ();
      
      Mailobj.from = new MailAddress ("mayun@qq.com"); Sender's email address   
      mailObj.To.Add ("mahuateng@qq.com");  Recipient email address
      mailobj.subject = "account activation";  Theme
      mailobj.body = Mailbody;  Body,
      mailobj.isbodyhtml = true;//indicates that the body content is HTML

      smtpclient smtp = new SmtpClient ();
      Smtp. Host = "smtp.sina.cn";     SMTP server name
      SMTP. useDefaultCredentials = true;
      Smtp. Credentials = new NetworkCredential ("mayun@qq.com", "pwd"); Sender's login name and password
      SMTP. Send (Mailobj);

Attention to detail:

One, SMTP

The SMTP (Simple Mail Transfer Protocol) is simply a mail Transfer protocol, which is a set of rules that send messages by source address to destination.

When in use, make sure that the service is open in the mail! Sina mailbox settings such as:

Second, the appearance of "Do not allow the use of mailbox names." Server response: Envolope sender mismatch with login user ... "error

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.