Mail MergeElastic Email supports mail merge functionality so that you can send a single job but support multiple recipients with personalized emails. Using this technique you can define an email template which contains special fields such as {firstname}, {lastname} or many others and send personalized emails in a very efficient way to your clients. For example: Dear {firstname} {lastname}, This is our monthly newsletter. We hope you have been enjoying our service. You can access your account at {link}. To use the mail merge you need to make two calls to the api. One to upload a CSV (comma separated values) data source file using the upload attachments api and a second call to the send api with the specified datasource. Step 1) Create a CSV file like the following: "ToEmail","FirstName","LastName" The first column of the data must be ToEmail and will be used as the recipients of the merged email. The other columns represent the data fields that you can use in your email. You can have as many columns as you need. If you have the header FirstName you can include that in your email template with {FirstName} and all references to that field will be replaced before sending. Step 2) Call the attachments upload api to upload the CSV file. To upload your attachment do a HTTP PUT of your attachment file to: https://api.elasticemail.com/attachments/upload?username=yourusername&api_key=yourapikey&file=test.csv Step 3) Call mailer send with the datasource value set: To use the send command POST to https://api.elasticemail.com/mailer/send with the following form values:
If sent correctly you will receive a response like: f74b9f96-f89a-4cfe-813f-5f86df1cb37f This is the transaction ID of your send job. You can use this transaction ID to check on the statistics of the given job using the Get Status api. Your email will be sent to each email address in the CSV file and the data will be merged with the CSV data. Note: There is a limit of 100000 emails / uploaded CSV file for larger jobs please split into separate calls. Code SamplesC#PHP |