I am using Sendgrid API v3 in a node.js and express environment.
I am using email dynamic templates and easily I can send custom text to the email templates.
But I need also to add attachments and I can't find documentation about that. I need to add attachments in 2 different ways:
There are email that need to have always the same attachments and it would be good for the email template to have its own attachments that is send to the customer inbox not matter what is the server data sent to sendgrid.
If a clinet buys an ebook, this file should be sent by the server, together with the rest of {{{data}}} to Sendgrid and this specific file should be delivered to the client as an attachments.
Can anyone say how to add attachments this way?
Thanks
Not sure if you still need it. But you can send emails using Dynamic Template and Attachments. Reference with their API Doc.
Sample code:
const sgMail = require('#sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const fs = require("fs");
pathToAttachment = `${__dirname}/attachment.pdf`;
attachment = fs.readFileSync(pathToAttachment).toString("base64");
const msg = {
to: 'test#example.com',
from: 'test#example.com',
subject: 'Sending with SendGrid is Fun',
templateId: "d-11111111111111111111111111",
attachments: [
{
content: attachment,
filename: "attachment.pdf",
type: "application/pdf",
disposition: "attachment"
}
]
};
sgMail.send(msg).catch(err => {
console.log(err);
});
For your 2 cases, why not build a function to send emails with parameters of dynamic template ID and attachments?
sendEmail(
templateId: string,
attachments: Attachment
)
Sendgrid attachments are limited to 30mb which might be too small for what you are trying to do. Sendgrid let's you use the digioh api to send files up to 2gb.
https://digioh.com/sendgrid
An alternative solution would be to send a callback url as text in the email that is linked to an endpoint on your express server that let's users download the data. In this case you would need some additional setup to make sure only users who purchased the items can download them.
Related
I'm using the gmail api to create a Gmail manager to my application (php). I'm using the documentation provided by google for php and all works correctly except the dynamic emails. I was looking for information about it but I didn't find anything.
I show you some examples of how I see it in my application and how it should be.
Pinteres email:
To access AMP Email using GMAIL API, you should probably get the raw email. This can be done by passing the format as raw. The details are available in the official documentation here.
Example code will be somewhat like below in javascript:
function getMessage(userId, messageId, callback) {
var request = gapi.client.gmail.users.messages.get({
'userId': userId,
'id': messageId,
'format' : 'raw'
});
request.execute(callback);
}
Note: Please note that the response will be raw base64 data.
If you are unable get it here, then Gmail should probably be stripping off the same from the response for security reasons. AMP Email is considered sensitive.
I'm working with Dynamics CRM 2016, I want to send an Email from crm using an email address that the user insert (the email Id is taken from a field in incident-Entity and not from crm-user) according to examples online the option is to use entityreference from another entity that will hold and get the Email address, is there a way not to use Entityreference but instead get my email address from a simple field on incident form?
You can use e-mail addresses that are not associated with e-mailaddress fields. It just requires a few steps.
In the UI navigate to Settings > System Settings > tab Email > header "Set Email form options".
Make sure setting "Allow messages with unresolved email recipients to be sent" is Yes.
Now you can use literal e-mail addresses like in this example:
var sender = new EntityCollection();
sender.Entities.Add(new Entity("activityparty")
{
["addressused"] = "me#home.test"
});
var recipients = new EntityCollection();
recipients.Entities.Add(new Entity("activityparty")
{
["addressused"] = "info#acme.test"
});
var eMail = new Entity("email")
{
["from"] = sender,
["to"] = recipients,
["subject"] = "Just a test",
["description"] = "Body of your e-mail"
};
organizationService.Create(eMail);
You can do it programmatically! You can send an email to a person who is not a Lead/Contact/Account.. The CRM will send email but it will show un resolved referenced when you open it in CRM
Update:
but instead get my email address from a simple field on incident form?
This is not possible in CRM UI. But possible using the code snippet from the blog link in comment. You have to query the textbox content and put in recipient party address.
(These two lines are for sending email to activity party email Id from associated record non-email field from CRM UI, without any code or customization for this particular scenario)
Unfortunately you cannot achieve it.
Only way is associated record.
I am really new to google script (never used before)and I think I am trying to run before i can walk
I need to be able to send and email to a list of people but each person will need a different attachment, I don't have a clue.
Any ideas on where i should look?
Here's a good place to start. It's a tutorial created by google.
https://developers.google.com/apps-script/articles/sending_emails
Here's Google Apps Script Class MailApp documentation.
https://developers.google.com/apps-script/reference/mail/mail-app
Another tutorial...
https://ctrlq.org/code/20118-mandrill-send-email-google
Hope that helps you get started.
In terms of structure on your spreadsheet, you will need a column list of email address and beside each email address so unique identification of the attachment that is to be sent. You would then loop through each row of that sheet and send an email for each address.
Refer the below code to send multiple mails with different email id, subject, body and attachment. Hope this helps!
function sendEmail(){
var openSpreadSheet = SpreadsheetApp.openById("<<YOUR SPREADSHEET ID>>").getSheetByName("Sheet1");
var data = openSpreadSheet.getRange(2,1,openSpreadSheet.getLastRow()-1,4).getValues();
for(var i=0;i<data.length;i++){
MailApp.sendEmail({
to:data[i][0],
subject: data[i][1],
htmlBody: data[i][2],
attachments:[DriveApp.getFileById(data[i][3]).getBlob()]
})
}
}
This is how the spreadsheet is configured.
I'm sending emails in Laravel with mandrill but I also want to save a copy of the email on the storage also (like mailoutput but in my own log folder)
Do you have any idea how to do that?
Thank you
Though you can log mails in Laravel, it seems that emails will not actually be sent at the same time.
A simple solution would be to log emails yourself:
Find where you send emails and add customized logging statements.
Mail::send('emails.welcome', array('key' => 'value'), function($message)
{
$message->to('foo#example.com', 'John Smith')->subject('Welcome!');
Log::info('You email content and receivers here');
});
I am able to send E-mail via the Webmail helper. However, I want to send the message with a body which contains HTML table. Can someone clarify if this is possible in Webmatrix webmail helper.
Yes it is possible. Just specify isBodyHtml: true in the Send method:
var customerRequest = "<p>Help!"</p>";
WebMail.Send(to: email,
subject: "Help request from - " + customerName,
body: customerRequest,
isBodyHtml: true
);
See here for more guidance: http://www.asp.net/web-pages/tutorials/email-and-search/11-adding-email-to-your-web-site