我有一个想要使用 SendGrid smtp 服务器发送电子邮件的 .NET Web 应用程序。
它是一个简单的单页应用程序,其代码位于Page_Load
. 我已经通过 Nu-Get 导入了对 SendGrid 的引用,并且引用也很好。代码在一段时间后到达 - 时出现超时错误transportSMTP.Deliver(myMessage)
。有人可以帮忙吗?
Imports System.Net
Imports System.Net.Mail
Imports SendGridMail
Imports SendGridMail.Transport
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Creating Email object for SendGrid
Dim myMessage As SendGrid = SendGrid.GenerateInstance()
myMessage.AddTo("RAMESHV@timken.com")
myMessage.From = New MailAddress("myemail@domain.com", "Vikram Avadhaani")
myMessage.Subject = "Testing the SendGrid Library"
myMessage.Text = "<p>Show's over Amigo!</p> <br/> It ain't over, 'till its over!"
'Create Credentials with UserName and Password
Dim mailCredentials = New NetworkCredential("<user id>", "<password>")
'Creating an SMTP Transport for sending email
Dim transportSMTP As SMTP = SMTP.GenerateInstance(mailCredentials) 'SMTP
Dim transportREST As REST = REST.GetInstance(mailCredentials) 'REST
'Send the email
transportSMTP.Deliver(myMessage)
'transportREST.Deliver(myMessage)
End Sub
End Class