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
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
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", PassWord)是不是这两句没加?
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
这个是我用的,可以发送的
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);
改为false
改为false没用的,都试过了,郁闷ing
{//Send mail use smtp.163.com server....
MailMessage objMailMessage;
objMailMessage = new MailMessage();
objMailMessage.From = new MailAddress("[email protected]","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);
}
}
-------这是我单独发送一个邮件的方法,你看看能不能帮忙。