新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
1.WEB开发,在ASP.Net中引用System.Web.Mail类
创新互联建站服务项目包括兴文网站建设、兴文网站制作、兴文网页制作以及兴文网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,兴文网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到兴文省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
2.使用JMail组件
第一种方法
MailMessage mm = new MailMessage();
mm.From = myReader["FromEmail"].ToString();
mm.To = myReader["ToEmail"].ToString();
mm.Subject = myReader["Subject"].ToString(); ;
mm.Body = strBody;
mm.BodyFormat = MailFormat.Html;
mm.Fields.Add("", "1"); //basic authentication
mm.Fields.Add("", myReader["UserName"].ToString()); //set your username here
mm.Fields.Add("", myReader["UserPassword"].ToString()); //set your password here
SmtpMail.SmtpServer = myReader["Smtp"].ToString();
SmtpMail.Send(mm);
第二种方法自己去下载Jmail组件,看资料
在Identity2.0里面封装了IIdentityMessageService接口,可以用来发送接收邮件。
看看
Imports System.Threading.Tasks
Imports System.Security.Claims
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin
Imports Microsoft.Owin.Security
public function SendAsync(message as IdentityMessage) as task
dim credentialUserName = "邮箱登录名"
dim sentFrom = "你的邮箱地址"
dim pwd= "邮箱登录密码";
dim client as new System.Net.Mail.SmtpClient("smtp服务器地址")
client.Port = 25'mtp邮件服务器端口
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
client.UseDefaultCredentials = false
dim credentials as new System.Net.NetworkCredential(credentialUserName, pwd)
client.EnableSsl = true
client.Credentials = credentials
dim mail as new System.Net.Mail.MailMessage(sentFrom, message.Destination)
mail.Subject = message.Subject
mail.Body = message.Body
return client.SendMailAsync(mail)
end function
发邮件,最好能有自己的邮件服务器,没有的话,也可以用网易或139邮箱等,示例代码:
SmtpClient client = new SmtpClient(smtp, smtpport)
{
UseDefaultCredentials = false,
Credentials = new NetworkCredential(登录名, 密码),
DeliveryMethod = SmtpDeliveryMethod.Network
};
var from = new MailAddress("发件人邮箱", "发件人姓名");
MailMessage message = new MailMessage
{
Sender = from,
From = from,
IsBodyHtml = false,
//Priority = MailPriority.High,
BodyEncoding = Encoding.UTF8
};
/*添加收件人列表*/
message.To.Add(new MailAddress("收件人邮箱", "收件人姓名"));
message.Subject = 邮件标题;
message.Body = 邮件内容;
//添加附件
message.Attachments.Add(new Attachment("C:\\abc.txt"));
client.Send(message);
将Catch这一段改写成
Catch
MessageBox.Show("邮件发送失败:" + Exception.Message)
检查一下出错的原因。