C# qq邮箱
现在qq邮箱无法通过Socket发送,是做了限制还是其他原因,哪位大侠能够指引下,感恩不尽。SmtpClientclient=newSmtpClient();client...
现在qq邮箱无法通过Socket发送,是做了限制还是其他原因,哪位大侠能够指引下,感恩不尽。
SmtpClient client = new SmtpClient();
client.Port = 465;
client.Host =“smtp.qq.com”;
client.Credentials = new System.Net.NetworkCredential("23312@qq.com", "123456");
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(from, pass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = enableSSL;
这里面的参数都已设置,却无法连接。
非ssl的端口改为25即可解决,但是如果是ssl的呢? 展开
SmtpClient client = new SmtpClient();
client.Port = 465;
client.Host =“smtp.qq.com”;
client.Credentials = new System.Net.NetworkCredential("23312@qq.com", "123456");
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(from, pass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = enableSSL;
这里面的参数都已设置,却无法连接。
非ssl的端口改为25即可解决,但是如果是ssl的呢? 展开
2个回答
展开全部
//单个发送
public static void SendMail(string mailSender, string displayName, string mailPwd, string sendTo, string subject, string messageBody, string smtpHost, bool isBodyHtml)
{
SendMail(mailSender, displayName, mailPwd, new string[] { sendTo }, subject, messageBody, smtpHost, isBodyHtml);
}
//多个发送
public static void SendMail(string mailSender, string displayName, string mailPwd, string[] sendToArr, string subject, string messageBody, string smtpHost, bool isBodyHtml)
{
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = false;
smtp.Host = smtpHost;
smtp.Port = 25;
smtp.UseDefaultCredentials = true;
//smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential(mailSender, mailPwd);
MailMessage mm = new MailMessage();
//实例化一个邮件类
mm.Priority = MailPriority.High;
mm.From = new MailAddress(mailSender, displayName, Encoding.GetEncoding(936));
mm.Sender = new MailAddress(mailSender, displayName, Encoding.GetEncoding(936));
if (sendToArr != null && sendToArr.Length > 0)
{
for (int i = 0; i < sendToArr.Length; i++)
{
mm.To.Add(sendToArr[i]);
}
}
mm.Subject = subject;
//邮件标题
mm.SubjectEncoding = Encoding.GetEncoding(936);
mm.IsBodyHtml = isBodyHtml;
//邮件正文是否是HTML格式
mm.BodyEncoding = Encoding.GetEncoding(936);
//邮件正文的编码, 设置不正确, 接收者会收到乱码
mm.Body = messageBody;
//邮件正文
smtp.Send(mm);
//发送邮件,如果不返回异常, 则大功告成了。
}
//调用
SendMail("发送账号", "姓名", "邮箱密码", "收件人", "标题", "内容 "smtp.qq.com", true);
追问
确定端口设为25能发送成功?
追答
反正我用起来没问题啊, 你试试呗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询