【问题标题】:Cannot send emails from .NET Web Application using SendGrid无法使用 SendGrid 从 .NET Web 应用程序发送电子邮件
【发布时间】:2012-09-17 22:13:01
【问题描述】:

我有一个想要使用 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

【问题讨论】:

  • 您是否确认您可以从运行此页面的 Web 服务器访问您的 SMTP 服务器?从 Web 服务器,您应该能够通过端口 25 远程登录到 SMTP 服务器。如果不能,请检查任一服务器(或两者之间)的防火墙。此外,一些常驻 AV 软件可能需要将您的 .NET 进程列入白名单,以允许其在特定端口上进行通信。
  • FWIW 你的 HTML 很糟糕。
  • 我正在从我的计算机本地运行此应用程序,我正在尝试使用端口 25。我还尝试将端口切换到 587。还尝试禁用 AV 并尝试在与提供的 LAN 不同的网络中工作中。我仍然遇到同样的错误。
  • 您指的是 myMessage.Text 吗?它可能只是一个普通的字符串......我添加了一些标签来增加它的趣味性。真正担心的是我无法连接到 sendGrid smtp 服务器

标签: .net smtp sendgrid


【解决方案1】:

找到了解决办法: - 在框架 4.0 上使用 Visual Studio(2012 或 2010)打包云(.Azure)项目 - 登录到 Windows Azure 门户并上传包。 如需帮助,请参考 - https://www.windowsazure.com/en-us/manage/services/cloud-services/how-to-create-and-deploy-a-cloud-service/

(愚蠢的我,当我面前有解决方案时,我只是担心代理和其他东西:P)

【讨论】:

    猜你喜欢
    • 2021-08-13
    • 2015-03-26
    • 1970-01-01
    • 2020-04-03
    • 2021-04-13
    • 2016-02-01
    • 1970-01-01
    • 2016-04-23
    • 2019-06-14
    相关资源
    最近更新 更多