在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
Private Sub Command1_Click()
Dim cm As New CDO.Message 'CDO.message是一个发送邮件的对象
'Set cm = CreateObject("CDO.Message") '创建对象 '引用路径:C:\Windows\system32\cdosys.dll'这个是要引用的,如果不引用,可以用这句也行
cm.From = "30687724@qq.com" '设置发信人的邮箱"
cm.To = "suxg@eshinetech.com" '设置收信人的邮箱
cm.Subject = "主题:邮件发送试验" '设定邮件的主题
'cm.TextBody = '邮件正文,使用文本格式发送邮件,如果太复杂了就不行了,要用下面这种
cm.HtmlBody = "邮件发送试验^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" '使用html格式发送邮件
cm.AddAttachment "D:\1.txt" '发的附件名与地址
stUl = "" '微软服务器网址,固定的,不用改的
With cm.Configuration.Fields
.Item(stUl "smtpserver") = "smtp.qq.com" 'SMTP服务器地址
.Item(stUl "smtpserverport") = 25 'SMTP服务器端口
.Item(stUl "sendusing") = 2 '发送端口
.Item(stUl "smtpauthenticate") = 1 '需要提供用户名和密码,0是不提供 '
.Item(stUl "sendusername") = "30687724" '发送方邮箱名称,不用输入@后面的东西
.Item(stUl "sendpassword") = "suxi87724" '发送方邮箱密码
.Update
End With
cm.Send '最后当然是执行发送了
Set cm = Nothing
'发送成功后即时释放对象
End Sub
下载一个jmail.dll引用到工程里
Private Sub Command1_Click()
On Error Resume Next
Dim rs_Jmail As New jmail.Message
Dim rs_Flag As Boolean
rs_Jmail.Charset = "GB2312"
rs_Jmail.Logging = True '启动日志
rs_Jmail.From = "abc@sina.com" '发件人电子邮件
rs_Jmail.FromName = "abc先生" '发件人姓名
rs_Jmail.AddRecipient "ddd@qq.com" '添加收件人
rs_Jmail.AddRecipient "mmm@sina.com", "mmm小姐" '添加更多收件人,第二个是收件人姓名
rs_Jmail.Subject = "邮件主题" '邮件主题
rs_Jmail.Body = "正文" '邮件正文
rs_Jmail.AppendText "389" '追加的一些文字
rs_Jmail.MailServerUserName = "abc@sina.com" '发件 的邮箱
rs_Jmail.MailServerPassWord = "abc" '发件人的邮箱密码
rs_Jmail.Priority = 3
rs_Flag = rs_Jmail.Send("smtp.sina.com") '发件邮箱的smtp服务器
If rs_Flag Then
MsgBox "邮件发送成功"
Else
MsgBox "邮件发送失败"
End If
Text1.Text = rs_Jmail.Log
Text1.Text = Text1.Text vbCrLf rs_Jmail.ErrorCode
End Sub
'创建发件连接,根据你的发送邮箱的SMTP设置填充
Dim smtp As New System.Net.Mail.SmtpClient("smtp.163.com", 25)
'发件邮箱身份验证,参数分别为 发件邮箱登录名和密码
smtp.Credentials = New System.Net.NetworkCredential("用户名", "密码")
'创建邮件
Dim mail As New System.Net.Mail.MailMessage()
'邮件主题
mail.Subject = "邮件主题"
'主题编码
mail.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312")
'邮件正文件编码
mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312")
'发件人邮箱
mail.From = New System.Net.Mail.MailAddress("example@163.com")
'邮件优先级
mail.Priority = System.Net.Mail.MailPriority.Normal
'HTML格式的邮件,为false则发送纯文本邮箱
mail.IsBodyHtml = True
'邮件内容
mail.Body = "邮件正文内容"
'添加收件人,如果有多个,可以多次添加
mail.To.Add("收件人地址")
'定义附件,参数为附件文件名,包含路径,推荐使用绝对路径
'如果不需要附件,下面三行可以不要
Dim a As New System.Net.Mail.Attachment("附件文件")
'附件文件名,用于收件人收到附件时显示的名称
a.Name = "附件文件名"
'加入附件,可以多次添加
mail.Attachments.Add(a)
'发送邮件
Try
smtp.Send(mail)
MessageBox.Show("发送成功")
Catch
MessageBox.Show("发送失败")
Finally
mail.Dispose()
End Try