源码:
SmtpClient client = new SmtpClient(); client.Host = SmtpHost; client.EnableSsl = true; //Error: need EHLO and AUTH first client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential(SendEmail, SendEmailPwd); client.DeliveryMethod = SmtpDeliveryMethod.Network; MailMessage message = new MailMessage(); //发件人 MailAddress addressFrom = new MailAddress(SendEmail, SendEmail); message.From = addressFrom; //收件人 paraRecipientEmails = paraRecipientEmails.Replace(";", ";"); String[] recipients = Regex.Split(paraRecipientEmails, ";", RegexOptions.IgnoreCase); foreach (String recipient in recipients) { MailAddress recipientEmail = new MailAddress(recipient); message.To.Add(recipientEmail); } //邮件标题 message.Subject = paraSubject; //邮件内容 message.Body = paraBody; //邮件编码 message.BodyEncoding = System.Text.Encoding.UTF8; //是否为HTML格式 message.IsBodyHtml = true; //至少有一个收件人 if (message.To.Count > 0) { client.Send(message); }
SmtpHost 跟 SendEmail 的域是一致的吗,还有SmtpHost的smtp服务开启没有
再把
UseDefaultCredentials设置为 false
我的smtphost进了腾讯的QQ邮箱开启了。
UseDefaultCredentials设置为 false,我刚才试了一下也不行
@Sam Xiao: 我这是可以的
client.Host = "smtp.qq.com";
client.EnableSsl = true; //Error: need EHLO and AUTH first
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("123456@qq.com", "发送短信后得到的一串字符");
......
发件人必须和client里的邮箱账号一样
是设置一样了。不行的。你不信试试
@Sam Xiao: 信