【发布时间】:2018-12-29 01:42:09
【问题描述】:
所以,我关注的是 guide,是的,我能够发送电子邮件,但我正在尝试添加密件抄送电子邮件,因为它的列表很长,我不希望它们显示在电子邮件的收件人列表。
使用 PHPMailer 发送时一切正常,这个question 似乎可以解决我的问题,但尽管我尝试了很多,但我还没有找到答案。
我现在是怎么做的:
$client = getClient();
if (is_string($client)){
exit ($client);
}
$service = new Google_Service_Gmail($client);
$user = 'me';
$strSubject = 'Correo GMail API' . date('M d, Y h:i:s A');
$strRawMessage = "From: Lauro Campos<jlcampost@concredito.com.mx>\r\n";
$strRawMessage .= "To: Metro Gio <greyeso@concredito.com.mx>\r\n";
$strRawMessage .= "Bcc: <cjlindorv@concredito.com.mx>,<cfgonzalezr@concredito.com.mx>,<jlcampost@concredito.com.mx>\r\n";
$strRawMessage .= 'Subject: =?utf-8?B?' . base64_encode($strSubject) . "?=\r\n";
$strRawMessage .= "MIME-Version: 1.0\r\n";
$strRawMessage .= "Content-Type: text/html; charset=utf-8\r\n";
$strRawMessage .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n\r\n";
$strRawMessage .= "mensaje <b>de prueba!\r\n";
// The message needs to be encoded in Base64URL
$mime = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
$msg = new Google_Service_Gmail_Message();
$msg->setRaw($mime);
//The special value **me** can be used to indicate the authenticated user.
$service->users_messages->send("me", $msg);
电子邮件确实已发送,每个收件人都会收到电子邮件,但密件抄送在电子邮件收件人列表中显示为:
para Metro, bcc: cjlindorv, bcc: cfgonzalezr, bcc: mí
当我使用 PHPMailer 通过 SMTP 发送,并使用 email->AddBCC() 方法时,在电子邮件中只显示 $email->AddAddress() 方法中添加的地址:
para Metro
我想用 Gmail API 做同样的事情,就像我说的,这个question 似乎有答案,但我需要更多信息。
他说:
You didn't provide your GMAIL API code but it might follow this outline:
$message = new Message();
# construct message using raw data from PHPMailer
$message->setSubjectBody(...);
$message->setTextBody(...);
$message->setHtmlBody(...);
# *** add the BCC recipients here ***
$message->addBcc("secret.recipient@google.com");
# send the message
$message->send();
我认为他正在谈论的 Message() 类将是 Google_Service_Gmail_Message(),但它不包含此类方法,这就是我遗漏的地方。
有人可以帮忙吗?
【问题讨论】:
-
您是说
to收件人可以看到其他密件抄送地址吗?不是说密件抄送收件人可以看到其他密件抄送? -
字符串连接似乎是解决这个问题的不好方法。甚至不清楚这项服务是什么。 SMTP 将处理 RCPT TO 的东西。我不知道什么 RFC 适用于这项服务。
-
它似乎工作正常,但由于我将自己包含在密件抄送中并且我使用我的帐户通过 Gmail API 发送它,我看到每个密件抄送,但我要求其他密件抄送收件人,他们只看到自己。我的坏。