
正文
vb.net发邮件源码 vba 邮件发送
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
要一段VB.NET发邮件的代码
'创建发件连接,根据你的发送邮箱的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
相关问答
Q1: Quoted-Printable编码的邮件解码,vb.net代码怎么写,谢谢
Dim Lines = System.IO.File.ReadAllLines("D:\zhege\qp.txt")
'邮件源代码应该是分行读取vb.net发邮件源码,替换掉这个数组就行。for代码段符合流vb.net发邮件源码的读取行方法(readline)。
Dim codeBuilder As New System.Text.StringBuilder
For Each code As String In Lines
code = code.Replace("==", "=")
If code.EndsWith("=") Then
code = code.Substring(0, code.Count - 1)
codeBuilder.Append(code)
ElseIf code "" Then
codeBuilder.AppendLine(code)
End If
Next
Dim reg As New System.Text.RegularExpressions.Regex("(=(\d|[A-F]){2}){1,}")
Dim match As System.Text.RegularExpressions.Match = Nothing
While reg.IsMatch(codeBuilder.ToString)
match = reg.Match(codeBuilder.ToString)
Dim Bytes As New List(Of Byte)
For Each cMatch As String In Replace(match.Value, "=", "", 1, 1).Split("="c)
Bytes.Add(CByte("h" cMatch))
Next
codeBuilder = codeBuilder.Replace(match.Value, System.Text.Encoding.Default.GetString(Bytes.ToArray))
End While
MsgBox(codeBuilder.ToString)
vb.net发邮件源码我只测试了一段qp代码,可能有误。如果qp不是Default编码,结果可能是乱码,需要注意
Q2: 如何用VB.Net收发邮件
在Identity2.0里面封装vb.net发邮件源码了IIdentityMessageService接口vb.net发邮件源码,可以用来发送接收邮件。
看看
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 = "vb.net发邮件源码你vb.net发邮件源码的邮箱地址"
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
关于vb.net发邮件源码和vba 邮件发送的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






