Mandril: How to attach ics invitation file to template?

℡╲_俬逩灬. 提交于 2019-12-21 13:04:19

问题


Hello,

I wonder if mandrill support ability to send mail with attached ics file.

Lets say I have some template.

function sendMailMandrillInvite($name, $contact_email, $textarea, $url, $template_name = 'invite-businesses'){
    $merge = 'true';
    $message = array('dest_mail' => $contact_email, 'merge' => $merge);

    $message['to'] = array(array('email' => $contact_email));

    $mergeVars[] = array(
         'rcpt' => $contact_email,
                     'vars' => array(
                      array('name' => 'contact_name', 'content' => $name),
                      array('name' => 'message', 'content' => $textarea),
                      array('name' => 'url', 'content' => $url)
                    )
                  );

         $template_content = array(array('name' => 'example name', 'content' => 'example content')); // dummy usage
         $message['merge_vars'] = $mergeVars;

        return $this->messages_send_template($template_name, $template_content, $message);
    }

What is the way to create template (HTML) and attach ics file to make mandrill mail to be "invitation"?

Is it possible?

Thanks,


回答1:


Currently, we aren't able to support the text/calendar multipart format—which is typically the format being used to add those event invitations in emails. When Mandrill's parser hits these kinds of message parts (text/calendar), it will skip over them since they don't conform to anything that it knows how to abstract away. It's not true text or HTML, attachment or embedded image. In the future, we'll look into adding special support for this particular form of message as it's quite popular, but I can't provide any specific ETA on when that might be. In the meantime, you might consider generating the .ics files and attaching them, just as you might with other types of attachments through the Mandrill API or SMTP integration.

The Mandrill Crew


So this is a way I used:

Template

{
    "key": "xxxxxxxxxxxxxxxxxx",
   "template_name": "fess1",
    "template_content": [
        {
            "name": "example name",
            "content": "example content"
        }
    ],
    "message": {
        "merge": "true",        
        "to": [
            {
                "email": "snaggs@gmail.com",
                "name": "Snaggs",
                "type": "to"
            }
        ],
        "headers": {
            "Reply-To": "snaggs@gmail.com",
            "MIME-Version": 1.0                
        },        
        "merge": true,
        "merge_vars": [
            {
                "rcpt": "snaggs@gmail.com",
                "vars": [
                    {
                        "name": "FNAME",
                        "content": "Snaggis"
                    }
                ]
            }
        ],
        "attachments": [
            { 
                "type": "text/calendar",
                "name": "meeting.ics",
                "content": "QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOi0vL01lZXRlci9tZWV0ZXIvL05PTlNHTUwgdjEuMC8vRU4NCkNBTFNDQUxFOkdSRUdPUklBTg0KTUVUSE9EOlJFUVVFU1QNCkJFR0lOOlZFVkVOVA0KRFRTVEFSVDoyMDE0MTAxOFQyMDMwMDBaDQpEVEVORDoyMDE0MTAxOFQyMTAwMDBaDQpVSUQ6MjAxNDEwMTVUMDAyODEzLTIyMzc4ODg2OEBtZWV0ZXIuY29tDQpEVFNUQU1QOjIwMTQxMDE0VDIxMjgxM1oNCk9SR0FOSVpFUjtDTj0ic25hZ2dzQGdtYWlsLmNvbSI7U0VOVC1CWT0iTUFJTFRPOnNvbWVhcHBAZ21haWwuY29tIjtMQU5HVUFHRT1zZTpNQUlMVE86c25hZ2dzQGdtYWlsLmNvbQ0KQVRURU5ERUU7Q1VUWVBFPUlORElWSURVQUw7Uk9MRT1SRVEtUEFSVElDSVBBTlQ7UEFSVFNUQVQ9TkVFRFMtQUNUSU9OO1JTVlA9VFJVRTtDTj1GZXNzeSBNO1gtTlVNLUdVRVNUUz0wOk1BSUxUTzpzbmFnZ3MyQGdtYWlsLmNvbQ0KREVTQ1JJUFRJT046ZGRkZCBtYW5kcmlsbA0KTE9DQVRJT046ZGRkZGRkIG1hbmRyaWxsDQpTVU1NQVJZOkNhbiBJIGxheSBsb3c/IENvb2sgc29tZSB5YXkteW8gMg0KVFJBTlNQOk9QQVFVRQ0KU0VRVUVOQ0U6MA0KU1RBVFVTOkNPTkZJUk1FRA0KRU5EOlZFVkVOVA0KRU5EOlZDQUxFTkRBUg=="
            }
        ]
    }
}

Where content is:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Meeter/meeter//NONSGML v1.0//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20141018T203000Z
DTEND:20141018T210000Z
UID:20141015T002813-223788868@meeter.com
DTSTAMP:20141014T212813Z
ORGANIZER;CN="snaggs@gmail.com";SENT-BY="MAILTO:someapp@gmail.com";LANGUAGE=se:MAILTO:snaggs@gmail.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Fessy M;X-NUM-GUESTS=0:MAILTO:snaggs2@gmail.com
DESCRIPTION:dddd mandrill
LOCATION:dddddd mandrill
SUMMARY:Can I lay low? Cook some yay-yo 2
TRANSP:OPAQUE
SEQUENCE:0
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR"

content base64_encode():

QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOi0vL01lZXRlci9tZWV0ZXIvL05PTlNHTUwgdjEuMC8vRU4NCkNBTFNDQUxFOkdSRUdPUklBTg0KTUVUSE9EOlJFUVVFU1QNCkJFR0lOOlZFVkVOVA0KRFRTVEFSVDoyMDE0MTAxOFQyMDMwMDBaDQpEVEVORDoyMDE0MTAxOFQyMTAwMDBaDQpVSUQ6MjAxNDEwMTVUMDAyODEzLTIyMzc4ODg2OEBtZWV0ZXIuY29tDQpEVFNUQU1QOjIwMTQxMDE0VDIxMjgxM1oNCk9SR0FOSVpFUjtDTj0ic25hZ2dzQGdtYWlsLmNvbSI7U0VOVC1CWT0iTUFJTFRPOnNvbWVhcHBAZ21haWwuY29tIjtMQU5HVUFHRT1zZTpNQUlMVE86c25hZ2dzQGdtYWlsLmNvbQ0KQVRURU5ERUU7Q1VUWVBFPUlORElWSURVQUw7Uk9MRT1SRVEtUEFSVElDSVBBTlQ7UEFSVFNUQVQ9TkVFRFMtQUNUSU9OO1JTVlA9VFJVRTtDTj1GZXNzeSBNO1gtTlVNLUdVRVNUUz0wOk1BSUxUTzpzbmFnZ3MyQGdtYWlsLmNvbQ0KREVTQ1JJUFRJT046ZGRkZCBtYW5kcmlsbA0KTE9DQVRJT046ZGRkZGRkIG1hbmRyaWxsDQpTVU1NQVJZOkNhbiBJIGxheSBsb3c/IENvb2sgc29tZSB5YXkteW8gMg0KVFJBTlNQOk9QQVFVRQ0KU0VRVUVOQ0U6MA0KU1RBVFVTOkNPTkZJUk1FRA0KRU5EOlZFVkVOVA0KRU5EOlZDQUxFTkRBUg==




回答2:


You should use https://icalendar.readthedocs.io/en/latest/index.html to generate simple ics file, convert it to base64 with https://docs.python.org/2/library/base64.html#base64.b64decode and send as attachment

[
  {
    'type': "text/calendar",
    'content': b64encode(
            make_isc_calendar(start, end, location, event)),
    'name': "calendar.ics",
  }
]


来源:https://stackoverflow.com/questions/26178760/mandril-how-to-attach-ics-invitation-file-to-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!