在Identity2.0里面封裝了IIdentityMessageService接口,可以用來發(fā)送接收郵件。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、成都小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了霍林郭勒免費(fèi)建站歡迎大家使用!
看看
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服務(wù)器地址")
client.Port = 25'mtp郵件服務(wù)器端口
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是一個(gè)發(fā)送郵件的對(duì)象
'Set cm = CreateObject("CDO.Message") '創(chuàng)建對(duì)象 '引用路徑:C:\Windows\system32\cdosys.dll'這個(gè)是要引用的,如果不引用,可以用這句也行
cm.From = "30687724@qq.com" '設(shè)置發(fā)信人的郵箱"
cm.To = "suxg@eshinetech.com" '設(shè)置收信人的郵箱
cm.Subject = "主題:郵件發(fā)送試驗(yàn)" '設(shè)定郵件的主題
'cm.TextBody = '郵件正文,使用文本格式發(fā)送郵件,如果太復(fù)雜了就不行了,要用下面這種
cm.HtmlBody = "郵件發(fā)送試驗(yàn)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" '使用html格式發(fā)送郵件
cm.AddAttachment "D:\1.txt" '發(fā)的附件名與地址
stUl = "" '微軟服務(wù)器網(wǎng)址,固定的,不用改的
With cm.Configuration.Fields
.Item(stUl "smtpserver") = "smtp.qq.com" 'SMTP服務(wù)器地址
.Item(stUl "smtpserverport") = 25 'SMTP服務(wù)器端口
.Item(stUl "sendusing") = 2 '發(fā)送端口
.Item(stUl "smtpauthenticate") = 1 '需要提供用戶名和密碼,0是不提供 '
.Item(stUl "sendusername") = "30687724" '發(fā)送方郵箱名稱,不用輸入@后面的東西
.Item(stUl "sendpassword") = "suxi87724" '發(fā)送方郵箱密碼
.Update
End With
cm.Send '最后當(dāng)然是執(zhí)行發(fā)送了
Set cm = Nothing
'發(fā)送成功后即時(shí)釋放對(duì)象
End Sub
下載一個(gè)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 '啟動(dòng)日志
rs_Jmail.From = "abc@sina.com" '發(fā)件人電子郵件
rs_Jmail.FromName = "abc先生" '發(fā)件人姓名
rs_Jmail.AddRecipient "ddd@qq.com" '添加收件人
rs_Jmail.AddRecipient "mmm@sina.com", "mmm小姐" '添加更多收件人,第二個(gè)是收件人姓名
rs_Jmail.Subject = "郵件主題" '郵件主題
rs_Jmail.Body = "正文" '郵件正文
rs_Jmail.AppendText "389" '追加的一些文字
rs_Jmail.MailServerUserName = "abc@sina.com" '發(fā)件 的郵箱
rs_Jmail.MailServerPassWord = "abc" '發(fā)件人的郵箱密碼
rs_Jmail.Priority = 3
rs_Flag = rs_Jmail.Send("smtp.sina.com") '發(fā)件郵箱的smtp服務(wù)器
If rs_Flag Then
MsgBox "郵件發(fā)送成功"
Else
MsgBox "郵件發(fā)送失敗"
End If
Text1.Text = rs_Jmail.Log
Text1.Text = Text1.Text vbCrLf rs_Jmail.ErrorCode
End Sub
'創(chuàng)建發(fā)件連接,根據(jù)你的發(fā)送郵箱的SMTP設(shè)置填充
Dim smtp As New System.Net.Mail.SmtpClient("smtp.163.com", 25)
'發(fā)件郵箱身份驗(yàn)證,參數(shù)分別為 發(fā)件郵箱登錄名和密碼
smtp.Credentials = New System.Net.NetworkCredential("用戶名", "密碼")
'創(chuàng)建郵件
Dim mail As New System.Net.Mail.MailMessage()
'郵件主題
mail.Subject = "郵件主題"
'主題編碼
mail.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312")
'郵件正文件編碼
mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312")
'發(fā)件人郵箱
mail.From = New System.Net.Mail.MailAddress("example@163.com")
'郵件優(yōu)先級(jí)
mail.Priority = System.Net.Mail.MailPriority.Normal
'HTML格式的郵件,為false則發(fā)送純文本郵箱
mail.IsBodyHtml = True
'郵件內(nèi)容
mail.Body = "郵件正文內(nèi)容"
'添加收件人,如果有多個(gè),可以多次添加
mail.To.Add("收件人地址")
'定義附件,參數(shù)為附件文件名,包含路徑,推薦使用絕對(duì)路徑
'如果不需要附件,下面三行可以不要
Dim a As New System.Net.Mail.Attachment("附件文件")
'附件文件名,用于收件人收到附件時(shí)顯示的名稱
a.Name = "附件文件名"
'加入附件,可以多次添加
mail.Attachments.Add(a)
'發(fā)送郵件
Try
smtp.Send(mail)
MessageBox.Show("發(fā)送成功")
Catch
MessageBox.Show("發(fā)送失敗")
Finally
mail.Dispose()
End Try