How can I add an unsubscribe link in a single email with Mailgun using SMTP?
Asked Answered
G

3

11

I am having trouble figuring out how to put an unsubscribe link in my email that is SMTP integrated with Mailgun.

Any thoughts?

Gabion answered 3/11, 2016 at 19:39 Comment(0)
D
14

Mailgun provides you with several unsubscribe variables:

1) %unsubscribe_url% -- link to unsubscribe recipient from all messages sent by given domain

2) %tag_unsubscribe_url% -- link to unsubscribe from all tags provided in the message

3) %mailing_list_unsubscribe_url% -- link to unsubscribe from future messages sent to a mailing list

If you include these variables in your emails, any recipient that clicks on the url will be automatically unsubscribed and those email addresses will be blocked from receiving future emails from that domain or message tag as appropriate.

reference https://documentation.mailgun.com/user_manual.html#tracking-unsubscribes

Dollarfish answered 25/11, 2016 at 6:47 Comment(3)
How can I use this variable in my email, where should I include it ?Wastage
@AlpeshJikadra did you find the solution?Monkshood
Yes @EhsanGondal, check my answer for the same question.Wastage
H
3

You can use it in a href link:

<a href="%unsubscribe_url%" target="_blank">Click here to unsubscribe</a>

Hairless answered 27/8, 2020 at 13:43 Comment(0)
W
1

Instead of giving entire domain as %unsubscribe_url% , it is better to add %tag_unsubscribe_url% only, so that all the tags which are part for the current email will get unscubscribe.

Here is the code

HTML link will be like

<a style="color: #8798AD;margin: 0;text-decoration: none;" href="%tag_unsubscribe_url%">Unsubscribe</a>

This will add unsubscribe link to all tags which are part of the current send email request.

so, it my send email request has 2 tags (i.e. Orage and Mango) this two tag will get unsubscribe by mailgun.

So if you send any email which contains one of these tag, then that email will not get deliver to client.

Java code example:

String from = "[email protected]";
String to = "[email protected]";
String subject="Sample email";
String replyTo="[email protected]";
String html = "<body><h1>Hello</h1><a style="color: #8798AD;margin: 0;text-decoration: none;" href="%tag_unsubscribe_url%">Unsubscribe</a></body>";

List<String> tags = new ArrayList<String>();
tags.add("Mango");
tags.add("Orange");

MailGunRequest mailGunRequest = new MailGunRequest(from, to, subject, html, tags, replyTo);

ResponseEntity<MailGunResponse> mailGunResponseResponseEntity = mailGunClient.sendEmail(mailGunRequest);

for more reference refere : https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-api

Wastage answered 14/12, 2021 at 5:37 Comment(2)
Does the tag_unsubscribe_url still exist in the api? I can not find it in the docsCoomer
@Coomer according to this document they still support. for reference check this: documentation.mailgun.com/docs/mailgun/user-manual/…Wastage

© 2022 - 2024 — McMap. All rights reserved.