flutter - 使用颤振通过 Sendgrid API 发送 png 附件?
问题描述
我正在尝试使用颤振通过 SendGrid API 发送 png 附件。我遵循了特定于附件邮件的 SendGrid API 文档(https://docs.sendgrid.com/for-developers/sending-email/migrating-from-v2-to-v3-mail-send#attachments),但我不断收到错误的请求响应消息(状态 400)。我不知道为什么。希望有人可以提供帮助。
static Future<int> sendEmail(
{String subject,
String content,
LoggedInUserNameLogin senderNameLogin,
String attachmentBase64,
String fileName}) async {
String supportEmail = 'test@email.com';
String fromEmail = 'test@email.com';
Map<String, String> headers = new Map();
headers["Authorization"] =
"Bearer SG.key";
headers["Content-Type"] = "application/json";
Uri url = Uri.parse('https://api.sendgrid.com/v3/mail/send');
content =
'$content<b> Sender User ID:<\/b> ${senderNameLogin.userID} <br><br> <b>Sender Name: <\/b>${senderNameLogin.name} <\/p>';
String emailBody = "{\n \"personalizations\":"
" [\n"
" {\n"
" \"to\": [\n"
" {\n"
" \"email\": \"$supportEmail\"\n"
" },\n"
" ]\n"
" }\n"
" ],\n"
" \"from\": {\n"
" \"email\": \"$fromEmail\"\n"
" },\n"
" \"subject\": \"$subject\",\n"
" \"content\":"
" [\n"
" {\n"
" \"type\": \"text\/html\",\n"
" \"value\": \"$content\"\n"
" }\n"
" ],\n"
" \"attachments\":"
" [\n"
" { \n"
" \"content\": \"$attachmentBase64\", \n"
" \"type\": \"jpg\",\n"
" \"name\": \"example_file\",\n"
" \"filename\": \"$fileName\", \n"
" \"disposition\": \"inline\", \n"
" \"content_id\": \"feedback_screenshot\" \n"
" } \n"
" ],\n"
" }";
return response.statusCode;
}
解决方案
推荐阅读
- python - 路径('',views.index,name='index'),AttributeError:模块'learning_logs.views'没有属性'index'
- python - 如何在 Matplotlib 中绘制一个非常大的数据集(日期、时间(x 轴)与记录的值(y 轴),每天每 15 分钟一次,持续一年)
- javascript - 如何将 JSON 数据从前端 JavaScript 发送到使用 Python Flask 构建的后端服务器
- shell - 从文件 1 中删除与文件 2 中特定列中的元素匹配的行
- javascript - 无法将反应应用程序部署到 github 页面
- r - 如何消除 ggplot 图例中的空白?
- java - YGuard 混淆失败并显示消息:yGuard 检测到 javax.xml.bind.ModuleUtil 的重复类定义
- c++ - 在嵌套需求中,为什么使用 `requires bool_constant
::value;` 而不是 `requires X;`? - notepad++ - 我如何在文件中使用记事本++搜索来显示特定的行
- python - Python pandas如何复制某些列