. Net sends emails through code, and. net code sends emails
Key code:
Namespace to be referenced:
Using System. Net. Mail;
Using System. Net;
1 MailMessage mailObj = new MailMessage (); 2 3 mailObj. from = new MailAddress ("mayun@qq.com"); // recipient email address 4 mailObj. to. add ("mahuateng@qq.com"); // recipient email address 5 mailObj. subject = "Account Activation"; // topic 6 mailObj. body = mailbody; // Body, 7 mailObj. isBodyHtml = true; // indicates that the body content is HTML 8 9 SmtpClient smtp = new SmtpClient (); 10 smtp. host = "smtp.sina.cn"; // smtp server name 11 smtp. useDefaultCredentials = true; 12 smtp. credentials = new NetworkCredential ("mayun@qq.com", "pwd"); // sender's login name and password 13 smtp. send (mailObj );
Note:
I. smtp
SMTP (Simple Mail Transfer Protocol) is a set of rules for sending Mail from the source address to the destination address.
Make sure that this service is enabled in the email! Sina mail settings include:
2. "email names are not allowed. The server response is: Envolope sender mismatch with login user .. ".