发送邮件总是提示: smtp 服务器要求安全连接或客户端未通过身份验证,有谁碰到过?

cherish58 2007-12-27 11:43:40
using System.Net.Mail;

System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.baosight.com";
client.UseDefaultCredentials = false;
//发件人邮箱和密码
client.Credentials = new System.Net.NetworkCredential("发件人邮箱地址", "密码");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//client.EnableSsl = true;
//发件人邮箱和收件人邮箱
System.Net.Mail.MailMessage message = new MailMessage("发件人邮箱地址", "收件人邮箱地址");
message.Subject = "系统邮件测试";
message.Body = "你好!";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = false;
try
{
client.Send(message);

Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('发送成功')</script>");
return;
}
catch (Exception ee)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ee.Message + "')</script>");
return;
}

发送时总是提示:smtp 服务器要求安全连接或客户端未通过身份验证,服务器响应为Authentication required
...全文
7338 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Delta 2008-09-15
  • 打赏
  • 举报
回复
System.Net.Mail下没有Fields.Add属性,郁闷呀!~~~~~~~~~
cherish58 2007-12-27
  • 打赏
  • 举报
回复
client.EnableSsl = true;
改为false

没用的,都试过了,郁闷ing
sunlovesea 2007-12-27
  • 打赏
  • 举报
回复
client.EnableSsl = true;
改为false
cherish58 2007-12-27
  • 打赏
  • 举报
回复
System.Net.Mail下没有Fields.Add属性
PY_0516 2007-12-27
  • 打赏
  • 举报
回复
以下代码可完成邮件发送:
using System.Net.Mail;
using System.Net.Mime;
using System.Net.Cache;
using System.Net;


MailMessage message = new MailMessage();
message.From = new MailAddress("@163.com");
message.To.Add("qq.com");
message.To.Add("qq.com");
message.Subject = "";
message.Body = "";

Attachment data = new Attachment(Page.MapPath(""));

message.Attachments.Add(data);

SmtpClient smtp = new SmtpClient("smtp.163.com");

smtp.Credentials = new NetworkCredential("", "");

smtp.Send(message);
kbryant 2007-12-27
  • 打赏
  • 举报
回复
Public Function SendMail()
Try
Dim mail As New MailMessage
mail.From = "<" + FromAddr + ">" + FromName
mail.To = toAddress
mail.Cc = CcAddress
mail.Bcc = BccAddress
mail.Subject = Subject
mail.Body = CreateBody(Body, New String() {strCallerBasyoID})

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true")
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserName)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", PassWord)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", Integer.Parse(smtpport))

System.Web.Mail.SmtpMail.SmtpServer = SearverIp
System.Web.Mail.SmtpMail.Send(mail)

Catch ex As Exception
HCLogger.WriteLog(HCLogger.LogLevel.ERR, "")
Dim strFormBase As HCFormBase = HCFormBase.GetForm("HCErrorMessageForm")

If Not strFormBase Is Nothing Then
strFormBase.CallingNotice(Nothing, Nothing, errorMessage)
End If
End Try
End Function
#End Region


这个是我用的,可以发送的。。。
kbryant 2007-12-27
  • 打赏
  • 举报
回复
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserName)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", PassWord)

是不是这两句没加?
xierfly 2007-12-27
  • 打赏
  • 举报
回复
private void sendMails(string tomail, string subject, string body,string fileroad)
{//Send mail use smtp.163.com server....
MailMessage objMailMessage;
objMailMessage = new MailMessage();
objMailMessage.From = new MailAddress("aa@163.com","xierfly");
objMailMessage.To.Add(tomail);
objMailMessage.IsBodyHtml = true;
objMailMessage.Subject = subject;
objMailMessage.Body = body;
//MailAttachment obj
Attachment mailattent = new Attachment(fileroad);//添加一个附件
objMailMessage.Attachments.Add(mailattent);

SmtpClient sclient = new SmtpClient("smtp.163.com");
sclient.Credentials = new System.Net.NetworkCredential("****Username*****","****password***");
try
{
sclient.Send(objMailMessage);
this.Response.Write("<script>alert('Sent Successfully.');</script>");
this.tbmail.Text = "";
}
catch(Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
}
}
-------这是我单独发送一个邮件的方法,你看看能不能帮忙。

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧