email - 使用 .net 在 Visual Studio 中发送电子邮件
问题描述
我的代码可以使用 smtp 工作到一定程度,它可以连接,但我无法对其进行授权。我现在什至通过 API 进行了连接。仍然无法发送电子邮件。我尝试了多种方法。这是在 VB.Net 上使用 VS2019 中的 VB。代码如下。谢谢
Imports GemBox.Email
Imports GemBox.Email.Smtp
Private Sub btmSendEmail_Click(sender As Object, e As EventArgs) Handles btmSendEmail.Click
Try
Dim message As New MailMessage(emailFrom, emailTo)
' Add subject.
message.Subject = "Send HTML Email with Image and Attachment"
message.BodyText = "Testing"
' Add HTML body with CID embedded image.
'Dim cid As String = "image001@gembox.com"
' message.BodyHtml = "<html><body>" &_
' "<p>Hi ,</p>" &_
' "<p>This message was created and sent with:</p>" &_
' "<p><img src='cid:" & cid & "'/></p>" &_
' "<p>Read more about it on <a href='https://www.gemboxsoftware.com/email'>GemBox.Email Overview</a> page.</p>" &_
' "</body></html>"
' Add image as inline attachment.
' message.Attachments.Add(New Attachment("%#gembox-email-logo.png%") With {.ContentId = cid})
' Add file as attachment.
' message.Attachments.Add(New Attachment("%#sample-file.pdf%"))
' Create new SMTP client and send an email message.
Using smtp As New SmtpClient("smtp.gmail.com")
smtp.Connect()
'Fails below step
smtp.Authenticate(emailFrom.ToString, emailPsw.ToString)
smtp.SendMessage(message)
End Using
Catch ep As Exception
MsgBox(ep.ToString)
End Try
End Sub
解决方案
推荐阅读
- maxscript - matrix3 的 scalerotationpart 到底是什么?[标语]
- python - @tf.function ValueError:在非首次调用用 tf.function 修饰的函数时创建变量,无法理解行为
- python - os.path.isfile 只识别一些文件而不是全部
- oracle - 使用 Oracle 钱包配置 Quartz 调度程序
- typescript - 是否需要安装 NPM
- python - 将一个类初始化为另一个类时出现问题显示错误代码
- python - Python:从网页获取加载的资源(如 chrome 开发工具)
- codenameone - VKB 始终打开的表单
- python-3.x - 基于属性去重/组合对象
- python - 如何在不损失准确性的情况下将暗网权重转换为 CoreML 模型?