How can I add an unsubscribe link in a single email with Mailgun using SMTP? - mailgun

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

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

You can use it in a href link:
Click here to unsubscribe

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 = "alpesh#jikadra.com";
String to = "alpesh#stack.com";
String subject="Sample email";
String replyTo="no-reply#jikadra.com";
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

Related

Django - Sending email with sendgrid templates - problem with a from address

I am using Sendgrid Dynamic Transactional Templates to send emails from my django project. The code can be seen below.
sg = SendGridAPIClient(djangoSettings.SENDGRID_KEY)
message = Mail(
from_email = some#email,
to_emails=some#email,
)
message.dynamic_template_data = {...
}
message.template_id = '....'
response = sg.send(message)
The email sends fine, but I need to use a from_email to send. I don't want to use an email they can reply to. I want some generic email associated with my sendgrid account, lets say mydomain.com. How can I go about solving that?
If you have authorized the domain in your Sendgrid account you can add any address you want so long as it's part of the authorized domain.
To do this go to, https://app.sendgrid.com/settings/sender_auth, press Authenticate your domain and follow the steps to add your domain. This includes configuring your DNS, DKIM and SPF. For more details on adding a domain visit here
Now in your code, you could add noreply#yourdomain.com, or any variation of that, as the from address so long as you authenticated yourdomain.com.

Accessing Current Recipient in Sitecore 8 Email Experience Manager

How do you get the raw contact id from the ec_contact_id on the URL created by EXM?
We are using Sitecore's EXM to send emails containing links for surveys to recipients. When the recipient takes the survey we want to tie the response back to the recipient. Since EXM puts a unique Id, ec_contact_id, for the contact (encrypted) we want to use that to determine the recipient versus adding our own custom id.
We found this article, https://briancaos.wordpress.com/2015/04/27/sitecore-8-exm-get-the-email-recipient-from-a-sublayout/, and tried implementing it in the Sitecore controller that gets called when the recipient clicks on the link but the resulting recipient name comes back as empty. We don't have a "sc_item_id" value so we tried "_id" and "ec_message_id" in its place but neither value produced a valid contact Id or recipient name. We also tried looking in MongoDB with the decrypted contactId but couldn't find a match.
You could try somthing like this:
//get value of the ec_contact_id parameter for current request
string queryString = WebUtil.GetQueryString( Sitecore.Modules.EmailCampaign.GlobalSettings.AnalyticsContactIdQueryKey);
var shortID = ShortID.TryParse(queryString, out shortID);
System.Guid contactId;
// where initializationVector is System.Guid of your email message item.
using (var cryptoServiceProvider = new GuidCryptoServiceProvider(System.Text.Encoding.UTF8.GetBytes(GlobalSettings.PrivateKey), initializationVector.ToByteArray()))
{
contactId = cryptoServiceProvider.Decrypt(shortID.Guid);
}
When you create a new user in an email list, Sitecore creates a record in the xDB Mongo database. You should be able to get the email address from the users profile.
Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails").Entries[Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails").Preferred]
Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails").Entries["work_email"]

How I can parse email to get original recipient of an email?

I had email source with me and want parse original recipient of email.
Lets say "user1#test.com" is receiving a email, but in "To" list user1#test.com, user2#test.com & user3#test.com are mentioned. I want to get only user1 from email source.
In initial analysis, email from mdeamon server contains "X-MDaemon-Deliver-To:" tag. Similarly email from Devcot mail server contains "Delivered-To:". But not getting generic parsing logic to get original email recipient.
How I can parse email to get original recipient of an email?
The best way to get this information is probably to parse the Received headers to see who the message was delivered for. In other words, look for a Received header that has a for token followed by x#x.com (where x#x.com will be the recipient).

Get the list of mail chimp subscribers in rails

I am working on a simple rails rails app and i have so many subscribers in my mail mailchimp account and i want to get my all subscribers and send the a mail from my rails app. How do i get my subscribers emails in an array.
my code sample is below
def send_now
#news_letter = NewsLetter.find(params[:id])
gb = Gibbon::API.new("xxx")
members = gb.lists.members({:id => 'xxx'})
#for each goes here to send the mail
redirect_to manage_news_letter_path(#news_letter), notice: "Sent news Letter"
end
I can get the list of subscribers but how can i split out their email into a for_each method in rails cos the format is i in a hash. any help thanks.
example output is below
{"email"=>"xx#xx.com", "id"=>"xx", "euid"=>"xx", "email_type"=>"html", "ip_signup"=>nil, "timestamp_signup"=>nil, "ip_opt"=>"208.68.37.172", "timestamp_opt"=>"2014-02-21 10:38:20", "member_rating"=>2, "info_changed"=>"2014-02-21 10:38:20", "web_id"=>xx, "leid"=>xx, "language"=>nil, "list_id"=>"xx", "list_name"=>"Blanckdigital website List", "merges"=>{"EMAIL"=>"xx#xx.com", "FNAME"=>"", "LNAME"=>""}, "status"=>"subscribed", "timestamp"=>"2014-02-21 10:38:20", "is_gmonkey"=>false, "lists"=>[], "geo"=>[], "clients"=>[], "static_segments"=>[], "notes"=>[]}
what i want is is just the email xx#xx.com alone for each of the subscribers

Redirect users to their specified email accounts with receiver and message fields pre-filled

I have an email address "myaddress#gmail.com". I have created a django form that has a text field and a button. I want to redirect anyone who types a message in the text box to their respective emails so that they can send the message they typed to "my address". This means that as they log in to their email accounts, their message boxes should already be filled with the message they typed and the receiver field should already have "myaddress#gmail.com". The problem is how to redirect the users to their email accounts and prefill the specified fields.
Can anyone help me please?
If the user has set a default email program, most of them will be triggered on mailto:. I know gmail works with mailto: as well, and its possible that other web email services might. All desktop email clients - again only if it is set as the default email program will work on mailto:
The format is:
mailto:[emailaddress]?header=value&header1=value1....&headerN=valueN
Here is an example that sets the subject of the email automatically:
Email me