110,533
社区成员
发帖
与我相关
我的任务
分享
//using System.Net.Mail;
System.Net.Mail.MailAddress EmailFrom = new System.Net.Mail.MailAddress("fanny110119@126.com", "Judge");
System.Net.Mail.MailAddress EmailTo = new System.Net.Mail.MailAddress("spmzfz@126.com", "Spmzfz126");
System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage(EmailFrom, EmailTo);
Email.Bcc.Add(new System.Net.Mail.MailAddress("zengfanzhi@21cn.com")); //密件抄送收件人
//Email.CC.Add(new System.Net.Mail.MailAddress("spmzfz@163.com")); // 抄送收件人
//Email.Attachments.Add(new System.Net.Mail.Attachment(@"F:\Other\MPC\STL.jpg"));
Email.Subject= "OK,Test By c#2008 ";
Email.Body ="Hello ,This is Test By c#2008\n" + System.DateTime.Now.ToString();
Email.SubjectEncoding= System.Text.Encoding.Default;
Email.BodyEncoding=System.Text.Encoding.Default;
Email.IsBodyHtml = true;
Email.Priority = System.Net.Mail.MailPriority.Normal;
System.Net.Mail.SmtpClient SmtpPC = new System.Net.Mail.SmtpClient("smtp.126.com", 25);
SmtpPC.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
SmtpPC.Credentials = new System.Net.NetworkCredential("fanny110119", "PS"); //new ...
//SmtpPC.UseDefaultCredentials = false; //this line code writein is wrong !
try
{
SmtpPC.Send(Email);
MessageBox.Show("OK,Send Email Complete !");
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
{
System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
}
第一个参数如果是163邮箱就写smtp.163.com
第二个参数发件人的帐号
第三个参数发件人密码
第四个参数收件人帐号
第五个参数主题
第六个参数内容.