使用SendGrid发送带有附件的电子邮件 [英] Sending an email with attachment using SendGrid
本文介绍了使用SendGrid发送带有附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var myMessage = new SendGridMessage();
myMessage.From = new MailAddress("info@email.com");
myMessage.AddTo("Cristian <myemail@email.com>");
myMessage.Subject = user.CompanyName + "has selected you!";
myMessage.Html = "<p>Hello World!</p>";
myMessage.Text = "Hello World plain text!";
// myMessage.AddAttachment("C:\test\test.txt");
var apiKey = "";
var transportWeb = new Web(apiKey);
transportWeb.DeliverAsync(myMessage);
基本上我可以使电子邮件正常工作,当我尝试添加附件时发送。我尝试了不同的路径和不同的写路径的方式,我不知道发生了什么问题,我发现每一个教程都显示它应该像这样工作。
Basically I can make the email work, and the moment I attempt to add an attachment it doesn't send it. I tried different paths and different ways of writing the path, I am not sure what is going wrong, every single tutorial I have found shows it should work like this.
推荐答案
我得到它的工作,原来我只需要一个虚拟路径:
I got it to work, turns out I just needed a virtual path:
myMessage.AddAttachment(Server.MapPath(@"~\img\logo.png"));
这篇关于使用SendGrid发送带有附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文