Sendmail: Send mail # region Sendmail: Send mail
/** // <Summary>
/// Sendmail: send an email
/// </Summary>
/// <Param name = "up"> </param>
/// <Param name = "usermail"> </param>
Public void Sendmail ()
{
// Mail Server Settings
Smtpclient MailServer = new smtpclient ();
MailServer. Host = "smtp.gmail.com"; // email sending server
MailServer. Credentials = new system. net. networkcredential ("account name", "password ");
MailServer. Time out = 5000;
MailServer. enablessl = true;
// Mail settings
Mailmessage mail = new mailmessage ();
Mailaddress mfrom = new mailaddress ("sender address ");
Mail. From = mfrom;
Mail. to. Add ("recipient address ");
Mail. Subject = "mail title ";
Mail. subjectencoding = system. Text. encoding. getencoding ("gb2312 ");
Mail. bodyencoding = system. Text. encoding. getencoding ("gb2312 ");
Mail. isbodyhtml = false;
Mail. Body = string. Format (@ "Congratulations! You have created a brand new *** network account.
Keep this email as a record because it contains important validation code that is required if you encounter problems or forget your password.
Your account :***
Your password :***
You can log on to your account through.
");
MailServer. Send (Mail );
}
# Endregion
After testing, Sina and Gmail can be used. 163 still has some problems.
1 <system.net> in Web. config
2 <mailsettings>
3 <SMTP>
4 <network host = "smtp.sina.com" Port = "25" username = "username" Password = "password"/>
5 </SMTP>
6 </mailsettings>
7 </system.net>