String file = server. mappath ("email_test.txt ");
System. Web. Mail. mailmessage MEs = new system. Web. Mail. mailmessage ();
Mes. To = "Send email ";
Mes. From = "receiving email ";
Mailattachment = new mailattachment (File );
Mes. attachments. Add (mailattachment );
Mes. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); // basic Permissions
Mes. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "Mail Box Name ");
Mes. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", "Send email password ");
Mes. bodyencoding = system. Text. encoding. utf8;
Mes. Body = "email body email content ";
// You can select the text rendering format below
Mes. bodyformat = mailformat. html;
Mes. Subject = "mail sending test ";
Smtpmail. smtpserver = "smtp.163.com ";
Smtpmail. Send (MES );
Response. Write ("sent successfully! ");
}
Catch (exception ex)
{
Response. Write (ex. Message );
}
// The following is an email sent by the POP3 protocol of the server.
Try
{
String file = server. mappath ("email_test.txt ");
Mailaddress from = new mailaddress ("zhengpengfei0791@163.com"); // instance a mail address
Mailaddress to = new mailaddress ("solomon_msn@live.cn"); // instance a mail receipt address
Mailmessage MEs = new mailmessage (from, );
Attachment myattachment = new attachment (file, system. net. Mime. mediatypenames. application. octet );
System. net. Mime. contentdisposition disposition = myattachment. contentdisposition;
Disposition. creationdate = system. Io. file. getcreationtime (File );
Disposition. modificationdate = system. Io. file. getlastwritetime (File );
Disposition. readdate = system. Io. file. getlastaccesstime (File );
Mes. attachments. Add (myattachment );
Mes. isbodyhtml = true;
Mes. Subject = "mail test ";
Mes. Subject = "email body email content
Smtpclient client = new smtpclient ();
Client. Host = request. userhostaddress;
Client. Port = 25;
Client. Credentials = new system. net. networkcredential ("toemail", "test ");
Client. Send (MES );
Response. Write ("email sent successfully! ");
}< br> catch (exception ex)
{< br> response. Write (ex. Message);
}