Bool result = false;
String mailaddress = configurationmanager. receivettings ["mailaddress"]. tostring ();
String mailname = configurationmanager. receivettings ["mailname"]. tostring ();
String mailpwb = configurationmanager. receivettings ["mailpwd"]. tostring ();
String mailsmtp = configurationmanager. receivettings ["mailsmtp"]. tostring ();
Mailmessage mailobj = new mailmessage ();
Mailobj. From = mailaddress;
Mailobj. To = xxxxxxx@126.com;
Mailobj. Subject = "your password ";
Mailobj. bodyformat = mailformat. html;
Mailobj. Body = "// Mailobj. bodyencoding = system. Text. encoding. default;
Mailobj. bodyencoding = system. Text. encoding. utf8;
Mailobj. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); // Basic Authentication
Mailobj. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", mailname); // set your username here
Mailobj. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", mailpwb); // set your password here
// Mailobj. bodyencoding = system. Text. encoding .;
// Mailobj. bodyencoding = system. Text. encoding. getencoding ("gb2312"); // The email encoding.
Smtpmail. smtpserver = mailsmtp;
Try
{
Smtpmail. Send (mailobj );
Result = true;
}
Catch (system. Exception ex)
{
Result = false;
}
Cause of error:
1. The encoding format of mail. bodyencoding is incorrect.
2. The account and password used to send the email are incorrect.
3. the SMTP address of the email sending server is set incorrectly.
In all the above three cases, email sending may fail and garbled exceptions may occur.