Send an email
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Net;
Using System.Net.Mail;
public partial class Sendemail:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Button1_Click (object sender, EventArgs e)
{
String s_from = TextBox1.Text.Trim (). ToString ();
String s_to = TextBox3.Text.Trim (). ToString ();
String Pwd=textbox2.text. Trim (). ToString ();
String S_body =textbox5.text.trim (). ToString ();
S_body = S_body. Replace ("\ r \ n", "<br/>");
S_body = S_body. Replace ("\ n", "<br/>");
S_body = S_body. Replace ("", "");
int i = S_from. IndexOf ("@");
String username = S_from. Substring (0,i);
mailaddress from = new MailAddress (s_from);
mailaddress to = new MailAddress (s_to);
MailMessage mailobj = new MailMessage (from, to);
mailobj. Subject = TextBox4.Text.Trim (). ToString ();
mailobj. BODY = S_body;
mailobj. Isbodyhtml = true;
mailobj. bodyencoding = System.Text.Encoding.GetEncoding ("GB2312");
mailobj. Priority = Mailpriority.high;
if (FileUpload1.PostedFile.ContentLength > 0)
{
Mailobj. Attachments.Add (new Attachment (FileUpload1.PostedFile.FileName));
}
SmtpClient smtp = new SmtpClient ("smtp.163.com");
Smtp. Host = "smtp.163.com";
Smtp. useDefaultCredentials = false;
Smtp. Credentials = new NetworkCredential (USERNAME,PWD);
Smtp. Deliverymethod = Smtpdeliverymethod.network;
try {
Smtp. Send (Mailobj);
Response.Write ("ok!");
}
Catch
{
Response.Write ("sorry!");
}
}
}
Because the mailbox is 163, so set the SMTP address is 163, if you use another mailbox, as long as the address of the SMTP to change it.