我该如何解决这个问题?
调用 /sendgrid-php/lib/helpers/mail/Mail.php 第 729 行中未定义的函数 SendGrid\mb_convert_encoding()
这是我的代码
<?php
require("./sendgrid-php/sendgrid-php.php");
$from = new SendGrid\Email(null, "example@example.com");
$subject = "Sending with SendGrid is Fun";
$to = new SendGrid\Email(null, "example@example.com");
$content = new SendGrid\Content("text/plain", "and easy to do anywhere, even with PHP");
// Send message as html
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$apiKey = getenv('my key');
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
print_r($response->headers());
echo $response->body();
Run Code Online (Sandbox Code Playgroud) 我使用 sendgrid v3 api 发送电子邮件。正如 V3 API 文档中提到的,我使用 custom_args 来获取事件回调中的参数,但它显示 400 个错误请求,而我使用 unique_args 时,电子邮件已发送,但事件回调不会发送我的 unique_args 参数。
data = {"content": [{"value": "dfafds", "type": "text/plain"}], "attachments": [{"content": "UEsDBB......QACAgIAAA=", "type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "content_id": "BqzZqz7LaqO9", "filename": "Contactmanager-company.xlsx", "disposition": "attachment"}], "from": {"email": "bishnusyangja@gmail.com"}, "personalizations": [{"to": [{"email": "bishnu@janakitech.com"}], "custom_args": {"email_msg_id": 106}, "subject": "daff"}]}
Run Code Online (Sandbox Code Playgroud)
来自发送网格的事件回调响应是
[{"sg_event_id": "aoDNXRAeRuaCAVRiutD-fg",
"sg_message_id": "epJqlw1JThGw--dDTC1oCQ.filter0099p3las1-8681-5B853F95-29.0",
"smtp-id": "epJqlw1JThGw--dDTC1oCQ@ismtpd0006p1maa1.sendgrid.net",
"timestamp": 1535459222,
"email": "bishnu@janakitech.com",
"event": "processed"}]
Run Code Online (Sandbox Code Playgroud)
我需要在事件回调响应中自定义参数,在此响应中我需要email_msg_id这里缺少什么?
发送批量电子邮件时,我收到几条错误消息:
553 5.1.3 The recipient address <john@example.com > is not a valid RFC-5321 address.
Run Code Online (Sandbox Code Playgroud)
电子邮件地址的格式看起来完全有效,因此我一开始无法弄清楚为什么这些邮件没有被发送。
我<%datetime%>在 SendGrid 模板中定义了一个变量。我根据这个命名约定决定遵循已经放置<%subject%>的主题行。我在示例中看到了不同的变量命名约定:https : //github.com/sendgrid/sendgrid-csharp/blob/master/SendGrid/Example/Example.cs#L41使用-name-and -city-,而https://github.com/sendgrid /sendgrid-csharp/blob/master/SendGrid/Example/Example.cs#L157使用%name%和%city%。
我只是假设变量替换基于简单的模式匹配,因此这些示例的对应模板包含完全相同的字符串。到目前为止,无论出于何种原因,这对我都不起作用。
string sendGridApiKey = ConfigurationManager.AppSettings["SendGridApiKey"].ToString();
var sendGrid = new SendGridAPIClient(sendGridApiKey);
string emailFrom = ConfigurationManager.AppSettings["EmailFrom"].ToString();
Email from = new Email(emailFrom);
string subject = "Supposed to be replaced. Can I get rid of this somehow then?";
string emaiTo = ConfigurationManager.AppSettings["EmailTo"].ToString();
Email to = new Email(emaiTo);
Content content = new Content("text/html", "Supposed to be replaced by the template. Can I get …Run Code Online (Sandbox Code Playgroud) 我想向多个收件人发送电子邮件.
我使用个性化,但每个人的电子邮件都出现在"收件人"字段中,这违反了他们的隐私.
我不想使用BCC,因为这通常直接导致垃圾(例如http://www.standss.com/blog/index.php/why-you-should-avoid-using-bcc-for-emails/) .
因此,我的问题是,如何在没有每个人电子邮件出现在"收件人"字段的情况下向多个收件人发送电子邮件.
我能看到的唯一选择是使用循环向每个电子邮件发送一个单独的请求,当我有大量电子邮件要发送时,这个循环非常耗费资源并且非常耗时!
我正在为 Java 使用 SendGrid API v3。它可以工作并完成工作。但是,如果发件人是hello@world.org,则收件人只会看到hello@world.org. 我试图完成的是,收件人也看到一个简单的名称(例如,Hello World <hello@world.org>),如下所示:
(上面注意,实际地址是noreply@k...,但前面是Kela Fpa。)
我怎样才能以编程方式做到这一点?
在SendGrids上使用USE案例之后,github确实设法向我发送了带有正确模板的电子邮件,但是替换显然不起作用,并且在生成的电子邮件中留为空白。服务器端:
const sgmailer = require("@sendgrid/mail");
sgmailer.setApiKey(process.env.SENDGRID_API_KEY);
sgmailer.setSubstitutionWrappers('{{', '}}');
const msg = {
to: '...',
from: 'sender@example.org',
subject: 'Hello world',
text: 'Hello plain world!',
html: '<p>Hello HTML world!</p>',
templateId: '...',
substitutions: {
name: 'Some One',
city: 'Denver',
},
};
sgmailer.send(msg)
Run Code Online (Sandbox Code Playgroud)
模板中的HTML:
const sgmailer = require("@sendgrid/mail");
sgmailer.setApiKey(process.env.SENDGRID_API_KEY);
sgmailer.setSubstitutionWrappers('{{', '}}');
const msg = {
to: '...',
from: 'sender@example.org',
subject: 'Hello world',
text: 'Hello plain world!',
html: '<p>Hello HTML world!</p>',
templateId: '...',
substitutions: {
name: 'Some One',
city: 'Denver',
},
};
sgmailer.send(msg) …Run Code Online (Sandbox Code Playgroud)我正在尝试将我的API代码从Sendgrid v2更新到实际的Sendgrid v3,所以我的代码以前看起来像这样:
public void sendCreatedUserEmail(User user) {
Email from = new Email(FROM);
from.setName(EMAIL_NAME);
String subject = "Hello" + user.getName();
Email to = new Email(user.getEmail());
Content content = new Content("text/html", "Something");
Mail mail = new Mail(from, subject, to, content);
mail.personalization.get(0).addSubstitution("{name1}", user.getName());
mail.personalization.get(0).addSubstitution("{name2}", user.getName());
mail.setTemplateId(USER_TEMPLATE_ID);
SendGrid sg = new SendGrid(SENDGRID_API_KEY);
Request request = new Request();
try {
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
Response response = sg.api(request);
} catch (IOException ex) {
logger.error(ex);
}
}
Run Code Online (Sandbox Code Playgroud)
经过几个小时的研究,我将v3更改为:(为了确保画面更清晰,我将所有内容分开)
public void sendCreatedUserEmail(User user) {
Mail mail = …Run Code Online (Sandbox Code Playgroud) 我可以根据用户行为配置 Sendgrid 动态模板这些选项之一吗?
SendGrid 模板是否支持条件逻辑,或者是否有其他方法可以通过动态模板实现此目的?(实际上我正在寻找 AMP 替代品)