C # the function of sending emails is found on the internet and socket is also used. The reason why I tried it is that the SMTP server is faulty. Here I use mailmessage and stmp.sohu.com of Sohu. The source code is as follows:
Protected void button#click (Object sender, eventargs E)
{
String from = ****** @ sohu.com;
String Fromer = "sender ";
String to = "***** @ 126.com ";
String toer = "recipient ";
String subject = "mail title ";
String file = "attachment address ";
String body = "sent content ";
String smtphost = "smtp.sohu.com ";
String smtpuser = "******* @ sohu.com ";
String smtppass = "*******";
Sendmail (from, Fromer, to, toer, subject, body, file, smtphost, smtpuser, smtppass );
}
/// <Summary>
/// C # email sending Function
/// </Summary>
/// <Param name = "from"> sender's email address </param>
/// <Param name = "Fromer"> sender </param>
/// <Param name = "to"> recipient's email </param>
/// <Param name = "toer"> recipient </param>
/// <Param name = "subject"> topic </param>
/// <Param name = "body"> content </param>
/// <Param name = "file"> attachment </param>
/// <Param name = "smtphost"> SMTP server </param>
/// <Param name = "smtpuser"> email </param>
/// <Param name = "smtppass"> password </param>
/// <Returns> </returns>
Public bool Sendmail (string sfrom, string sfromer, string sto, string stoer, string ssubject, string sbody, string sfile, string ssmtphost, string ssmtpuser, string ssmtppass)
{
//// Set the from and to addresses
Mailaddress from = new mailaddress (sfrom, sfromer );
Mailaddress to = new mailaddress (STO, stoer );
//// Create a mailmessage object
Mailmessage omail = new mailmessage (from, );
/// Add an attachment
If (sfile! = "")
{
Omail. attachments. Add (new attachment (sfile ));
}
//// Mail title
Omail. Subject = ssubject;
//// Email content
Omail. Body = sbody;
//// Email format
Omail. isbodyhtml = false;
//// Email Encoding
Omail. bodyencoding = system. Text. encoding. getencoding ("gb2312 ");
//// Set the mail priority to high
Omail. Priority = mailpriority. High;
//// Send an email
Smtpclient client = new smtpclient ();
/// Client. usedefacrecredentials = false;
Client. Host = ssmtphost;
Client. Credentials = new networkcredential (ssmtpuser, ssmtppass );
Client. deliverymethod = smtpdeliverymethod. Network;
Try
{
Client. Send (omail );
Return true;
}
Catch (exception ERR)
{
Response. Write (ERR. Message. tostring ());
Return false;
}
Finally
{
//// Release resources
Omail. Dispose ();
}
}