如何使用vb.net使用mailkit发送电子邮件?
我正在尝试使用MailKit和vb.net代码发送电子邮件。
电子邮件发送了电子邮件,除了电子邮件的正文始终为空白。
这是我的代码。我怀疑这一行的问题是:
message.Body = New TextPart(TextFormat.Plain) With {
.Text = "Test Message"
}
我将代码从c#转换为vb.net,不知道这是否是vb.net中的正确语法来设置文本属性?
'Create email message
Dim email As MimeMessage = New MimeMessage()
email.From.Add(MailboxAddress.Parse(MyFromEmail))
email.To.Add(MailboxAddress.Parse(MyToEmail))
email.Subject = "Test Email Subject"
Dim message As MimeMessage = New MimeMessage()
message.Body = New TextPart(TextFormat.Plain) With {
.Text = "Test Message"
}
'Send email
Dim smtp As MailKit.Net.Smtp.SmtpClient = New MailKit.Net.Smtp.SmtpClient()
smtp.Connect(MySmtpServer, MySmtpServerPort, MailKit.Security.SecureSocketOptions.SslOnConnect)
smtp.Authenticate(MySendingEmail, MySendingPassword)
smtp.Send(email)
smtp.Disconnect(True)
I'm trying to send an email using MailKit and VB.net code.
The email is sending except the body of the email message is always blank.
Here is my code. I suspect the problem is with this line:
message.Body = New TextPart(TextFormat.Plain) With {
.Text = "Test Message"
}
I converted the code from C# to VB.net and don't know if this is the correct syntax in VB.net to set the Text property?
'Create email message
Dim email As MimeMessage = New MimeMessage()
email.From.Add(MailboxAddress.Parse(MyFromEmail))
email.To.Add(MailboxAddress.Parse(MyToEmail))
email.Subject = "Test Email Subject"
Dim message As MimeMessage = New MimeMessage()
message.Body = New TextPart(TextFormat.Plain) With {
.Text = "Test Message"
}
'Send email
Dim smtp As MailKit.Net.Smtp.SmtpClient = New MailKit.Net.Smtp.SmtpClient()
smtp.Connect(MySmtpServer, MySmtpServerPort, MailKit.Security.SecureSocketOptions.SslOnConnect)
smtp.Authenticate(MySendingEmail, MySendingPassword)
smtp.Send(email)
smtp.Disconnect(True)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于身体的设置,我将使用健美运动员:
For settings the body I would use the BodyBuilder class: