c# - 使用 SendGrid C# 在电子邮件正文中渲染 SVG
问题描述
我必须在电子邮件正文中放置一个简单的图像以及超链接。要发送电子邮件,我使用的是 SendGrid API。
我的 C# 代码:
public async Task SendEmailAsync(EmailDeliveryModel model) {
var response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
var client = new SendGridClient(ConfigurationManager.AppSettings[CommonObject.SendGridKey]);
var msg = new SendGridMessage();
msg.SetFrom(new EmailAddress(model.SourceEmail));
var recipients = new List();
//multiple recipients
foreach(string emailAddress in model.DestinationEmail.Trim(',').Split(',')) {
recipients.Add(new EmailAddress(emailAddress.Trim()));
}
msg.AddTos(recipients);
msg.SetSubject(model.Subject);
if (model.ContentType.Equals(CommonObject.ContHTML, StringComparison.OrdinalIgnoreCase)) {
msg.AddContent(MimeType.Html, model.EmailContent + "\n \n \n \n \n");
} else {
msg.AddContent(MimeType.Html, model.EmailContent + "\n \n \n \n \n");
}
var sendGridresponse = await client.SendEmailAsync(msg);
if (sendGridresponse.StatusCode == System.Net.HttpStatusCode.Accepted) {
response.StatusCode = System.Net.HttpStatusCode.OK;
}
return response;
}
在 EmailContent 中,我将 html 内容与 SVG 一起注入,但 SVG 并未在电子邮件中呈现。但是,如果我在浏览器中尝试相同的 html,它就可以工作。
如何在电子邮件正文中发送图像以及超链接?
解决方案
推荐阅读
- flutter - Flutter FAILURE:构建失败,未设置异常密钥库文件
- apache-kafka - 使用 Apple M1 启动 Confluent Control Center 时出错
- javascript - 使用 html2pdf.js 的 PDF 中的空白页
- python - 函数定义中的常量无法识别
- python - 按日期升序排列的日期栏频率条形图
- google-chrome - Chrome 权限:System.display
- python - 从在线托管的 MP4 文件中捕获随机帧
- python - Python - 在执行应用程序时安装 TTF 字体命令
- regex - 查找是否后跟非数字或文件结尾
- r - 使用 data.table 按组进行最后一次观察