【问题标题】:sending email with attachment from Azure using SendGrid使用 SendGrid 从 Azure 发送带有附件的电子邮件
【发布时间】:2018-04-15 21:26:14
【问题描述】:

如何使用 SendGrid 从 Azure 中的 VM 发送带有附件的电子邮件?

我添加了myMsg.AddAttachment 并提供了参数。执行时我没有收到任何错误,但电子邮件永远不会被发送。如果我注释掉这一行, 电子邮件被发送。

我做错了什么?这是在 ASP.net VB 中。

【问题讨论】:

  • 查看 SendGrid 门户中的投递报告,可能是收件人的 MX 退回,原因应该在那里。
  • 如果有更多关于复制代码示例和详细异常的信息会更有帮助。
  • 该附件的文件大小是多少(可能有限制)
  • 这是一个小的 Excel 文件。大小应该不是问题。

标签: asp.net vba azure sendgrid


【解决方案1】:

我用Sendgrid 9.9.0检查了这个问题,这里是代码sn-p:

'instantiate the SendGridMessage object 
Dim sendGridMessage = New SendGridMessage()
sendGridMessage.From = New EmailAddress("xxxxxx@hotmail.com", "BruceChen1019")
sendGridMessage.AddTo(New EmailAddress("xxxxx@gmail.com", "Bruce Chen"))
sendGridMessage.PlainTextContent = "Hello World!"
sendGridMessage.Subject = "Hello Email!"

'instantiate the Attachment object
Dim attachment = New Attachment()
attachment.Filename = "helloword.txt"
attachment.Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("hello world!!!"))
attachment.Type = "text/plain"
Dim attachments = New List(Of Attachment)
attachments.Add(attachment)
sendGridMessage.AddAttachments(attachments)

'send the email
Dim Response = client.SendEmailAsync(sendGridMessage).Result
Console.WriteLine(Response.StatusCode) //202 Accepted

Console.ReadLine()

测试:

另外,对于您的附件文件,您需要根据文件扩展名为attachment.Type设置正确的MIME类型,并对您的文件内容进行Base64编码。

另外,您需要关注Attachments limitations。您可以关注 evilSnobu 关于前往 SendGrid 门户解决此问题的评论。

【讨论】:

    猜你喜欢
    • 2016-10-23
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多