Note: I was planning to use Sina ,(SMTP.Sina.com), but after testing, I feel this is very unstable. So I switched to the SMTP service of Gmail, and it felt very stable and fast. Record it to help later!
Method 1
Bytes ------------------------------------------------------------------------------------------------------
// Using system. net. mail;
Mailmessageage message = new mailmessageage ();
Message. From = new mailaddress ("User@gmail.com", "Your displayname ");
Message. to. Add (New mailaddress ("To@gmail.com"); // the email you wantTo sendEmail
Message. Subject = "A test email"
Message. isbodyhtml = true;
Message. bodyencoding = system. Text. encoding. utf8;
Message. Body = "This is just a simple test! <Br> Jack"
Message. Priority = mailpriority. High;
Smtpclient client = new smtpclient ("smtp.gmail.com", 587); // 587; // port used by Gmail
Client. Credentials = new system. net. networkcredential ("User@gmail.com", "*****"); // your user name & Password
Client. enablessl = true; // encrypted by SSL
Object userstate = message;
Try
{
Client. Send (Message );
Response. Write ("mail sent to" + message. to. tostring () + "<br> ");
}
Catch (exception ee)
{
Response. Write (EE. messageage + "<br>" + ee. innerexception. messageage );
}
Method 2
Bytes ------------------------------------------------------------------------------------------------------
// Http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx
// Using system. net. mail;
Mailmessage message = new mailmessage ();
Message. From = new mailaddress ("User@gmail.com ");
Message. to. Add (New mailaddress ("to@gmail.com "));
Message. Subject = "this is my subject"
Message. Body = "this is the content"
Smtpclient client = new smtpclient ();
Client. enablessl = true;
Try
{
Client. Send (Message );
Response. Write ("mail sent to" + message. to. tostring () + "<br> ");
}
Catch (exception ee)
{
Response. Write (EE. Message );
}
// In web. config
<System.net>
<Mailsettings>
<SMTP from = "from@gmail.com">
<Network host = "smtp.gmail.com" Port = "587" username = "User@gmail.com" Password = "Your PWD"/>
<! -- If has 'defaultcredentials = "true" ', using Gmail can not sendSuccess-->
</SMTP>
</Mailsettings>
</System.net>
Jack is here: Focus on. NET, Asp.net, C #, LINQ and so on