老是报的错误是System.Net.Mail.SmtpException类型的异常
邮箱不可用。 服务器响应为: Óû§±»Ëø¶¨
麻烦大家帮忙看下
private bool SendMail(string sendstr, string sjstr,string titlestr,string conetstr,string stmpstr,string pwd)
{ MailAddress from = new MailAddress(sendstr); //收件人地址 MailAddress to = new MailAddress(sjstr); System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to); //添加附件,判断文件存在就添加
message.Subject = titlestr; // 设置邮件的标题 message.Body = conetstr; //发送邮件的正文 message.BodyEncoding = System.Text.Encoding.Default; //MailAddress other = new MailAddress("[email protected]"); //message.CC.Add(other); //添加抄送人 //创建一个SmtpClient 类的新实例,并初始化实例的SMTP 事务的服务器 SmtpClient client = new SmtpClient();
client.Host = stmpstr; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.EnableSsl = false; //身份认证 client.Credentials = new System.Net.NetworkCredential(sendstr, pwd); bool ret = true; //返回值 try
{ client.Send(message); } catch (SmtpException ex)
{ MessageBox.Show(ex.Message); ret = false; } catch (Exception ex2)
{ MessageBox.Show(ex2.Message); ret = false; } return ret; }
邮箱不可用。 服务器响应为: Óû§±»Ëø¶¨
麻烦大家帮忙看下
private bool SendMail(string sendstr, string sjstr,string titlestr,string conetstr,string stmpstr,string pwd)
{ MailAddress from = new MailAddress(sendstr); //收件人地址 MailAddress to = new MailAddress(sjstr); System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to); //添加附件,判断文件存在就添加
message.Subject = titlestr; // 设置邮件的标题 message.Body = conetstr; //发送邮件的正文 message.BodyEncoding = System.Text.Encoding.Default; //MailAddress other = new MailAddress("[email protected]"); //message.CC.Add(other); //添加抄送人 //创建一个SmtpClient 类的新实例,并初始化实例的SMTP 事务的服务器 SmtpClient client = new SmtpClient();
client.Host = stmpstr; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.EnableSsl = false; //身份认证 client.Credentials = new System.Net.NetworkCredential(sendstr, pwd); bool ret = true; //返回值 try
{ client.Send(message); } catch (SmtpException ex)
{ MessageBox.Show(ex.Message); ret = false; } catch (Exception ex2)
{ MessageBox.Show(ex2.Message); ret = false; } return ret; }
将你的邮箱先在outlook里面设置了,能发送的话,再看代码的问题.
现在一般申请的免费邮箱是不支持smtp外发的.早些年申请的可以.
好像sina还可以 你换个sina的试试 应该就是这个原因
string s_to = "[email protected]";
string pwd = "12345abc";
string s_body = "Hi,<br><br> Attached is a PDF document of Work Order Report from JBS:" + r.RequestNo + ".";
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 = this.tbSubject.Text.ToString();
mailobj.Body = s_body;
mailobj.IsBodyHtml = true;
mailobj.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
mailobj.Priority = MailPriority.High;
mailobj.Attachments.Add(new Attachment(path)); smtp.Host = "smtp.163.com";
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(username, pwd);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mailobj);--------------------------
你试试这个,希望对你有用
那怎么才能拿到SMTP功能
??
总之,拿到邮箱了先在outlook里面试试.
我试验过 sina 163 qq邮箱都会有错误建议你使用自己公司的企业邮箱
我试过用自己公司的企业邮箱发送可以成功
GMAIL和HOTMAIL可以试试
确认网络、通讯状态是否正常。
确认是否需要SMTP、SSL等身份验证。
使用google.qq邮箱试试
或用jmail发送邮件