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.