JSFiddle - React, Tailwind, and code Playground
Snippet for sending email with attachments with Fliplet
by Hugo Carneiro
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.api.fliplet.com/sdk.js?packages=fliplet-communicate&auth_token=eu--session--0f2bcb7553732d541389fe00bc36cb1c-359-825-6900"></script>
<div class="container">
<input type="text" class="form-control" id="something" placeholder="Enter your email"/>
<div class="btn btn-primary">Send me a calendar invite</div>
<div class="text-danger"></div>
</div>
JavaScript
Fliplet().then(function () {
var calEvent = {
name: '',
file: ''
};
var emailTemplate = "";
function sendEmail(from, body, subject, to, calEvent, button) {
var options = {
"from_name": from,
"to": [{
"email": to,
"name": "",
"type": "to"
}],
"html": body,
"subject": subject,
"headers": {
"Reply-To": "[email protected]"
},
"attachments": [{
"type": "text/calendar",
"name": calEvent.name,
"content": calEvent.file
}]
};
Fliplet.Communicate.sendEmail(options).then(function() {
button.html('Send me a calendar invite');
})
.catch(function(error) {
button.html('Send me a calendar invite');
$('.text-danger').html(error.body.message);
});
}
$('.btn').on('click', function() {
$(this).html('Sending...');
$('.text-danger').html('');
var userEmail = $('#something').val();
if (userEmail) {
sendEmail('[email protected]', emailTemplate, 'Your calendar', userEmail, calEvent, $(this))
} else {
$(this).html('Send me a calendar invite');
$('.text-danger').html('You need to enter the email first.');
}
});
});