【问题标题】:How to send google calendar invite using swiftmailer library如何使用 swiftmailer 库发送谷歌日历邀请
【发布时间】:2015-12-10 17:34:28
【问题描述】:

以下代码将 ical 邀请完美地发送到我们的内部邮件系统。但是,在 gmail 中,我只看到一个 meeting.ics 文件附件。我没有看到要求我回复的块。我错过了什么?

require_once 'swiftmailer/lib/swift_required.php';

$messageObject = Swift_Message::newInstance();
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername('me@gmail.com')
  ->setPassword('passwd');

$messageObject->setContentType("multipart/alternative");
$messageObject->addPart("Email message body goes here", "text/html");

$messageObject->setSubject("Subject line goes here")
  ->setFrom('support@me.com', 'ME');

$messageObject->setTo(array('me@gmail.com'));

$ics_content = file_get_contents("cal.ics");
$ics_attachment = Swift_Attachment::newInstance()
  ->setBody(trim($ics_content))
  ->setEncoder(Swift_Encoding::get7BitEncoding());
$headers = $ics_attachment->getHeaders();
$content_type_header = $headers->get("Content-Type");
$content_type_header->setValue("text/calendar");
$content_type_header->setParameters(array(
  'charset' => 'UTF-8',
  'method' => 'REQUEST'
));
$headers->remove('Content-Disposition');

$messageObject->attach($ics_attachment);

$mailObject = Swift_Mailer::newInstance($transport);
$mailObject->send($messageObject);

这是“cal.ics”文件:

BEGIN:VCALENDAR
PRODID:-//support@me.com//support@me.com//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20150929T133000Z
DTEND:20150929T190000Z
DTSTAMP:20150911T210204Z
ORGANIZER;CN=support@me.com:MAILTO:ME
UID:NRT Sales Pro
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE;CN=support@me.com;X-NUM-GUESTS=0:NRT Sales Pro
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=NRT Sales Pro;X-NUM-GUESTS=0:NRT Sales Pro
CREATED:20150911T210204Z
LAST-MODIFIED:20150911T210204Z
LOCATION:Dix Hills, NY Education Center | 1206 E Jericho Tpke, Huntington NY 11743
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Discover the Difference
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

【问题讨论】:

    标签: php gmail google-calendar-api icalendar swiftmailer


    【解决方案1】:

    关于您的 icalendar 数据,您的 ORGANIZER 或 ATTENDEE 属性均无效。他们每个人都应该有一个有效的 mailto: uri 作为值(如果您尝试从 gmail 接受,则至少其中一个对应于 gmail 帐户)。

    那么您需要非常小心您发送的电子邮件的 MIME 结构。见Multipart email with text and calendar: Outlook doesn't recognize ics

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      • 2019-01-02
      • 1970-01-01
      • 2015-12-19
      • 2014-05-04
      • 2013-06-09
      • 1970-01-01
      相关资源
      最近更新 更多