vs2005sendmail
1:
using System.Net.Mail;
public static void SendWebMailAndAttach(string from,string to,string subject,string body)
{
SmtpClient Client = new SmtpClient("127.0.0.1");
Client.DeliveryMethod = SmtpDeliveryMethod.Network; //用到了System.Net 命名空間
Client.Credentials = new System.Net.NetworkCredential("touch/weishuai ", "56");
//"touch/weishuai "域使用者
// "56"密碼
MailMessage Message = new MailMessage(from, to, subject, body);
Message.BodyEncoding = System.Text.Encoding.UTF8;
//Client.EnableSsl = true;
//Message.BodyEncoding = System.Text.Encoding.Unicode;
//Message.SubjectEncoding = System.Text.Encoding.Unicode;
Client.Send(Message);
Message.Dispose();
}
protected void Button1_Click(object sender, EventArgs e)
{
string from="[email protected]";
string to="[email protected]";
string subject="ni hao a ";
string body="yes good";
SendWebMailAndAttach(from,to,subject,body);
Response.Write("ok");
}
2.: 伺服器拒絕了一個或多個收件人位址。伺服器響應為: 550 5.7.1 Unable to relay for ..................預設SMTP虛拟伺服器--屬性--通路 -- 中繼--“加入127.0. 0.1” ;
就行了
3:System.Net.NetworkCredential("touch/weishuai", "56");
我在SMTP服務裡設定了。WIN驗證
屬性--通路--通路控制--匿名和內建WIN驗證
4:注意防毒軟體的關閉。