Skip automatic "Unsubscribe Me" feature for just one e-mail transaction - mailgun

I have a mailgun account and have been using it to send e-mails.
I've enabled the automatic "Unsubscribe Me" feature that makes it so that all e-mails sent from my account would have the "Unsubscribe" link.
However, I have an e-mail that I would like to get sent only once and would like to disable the unsubscribe me feature for this one particular e-mail.
How do I turn off the unsubscribe me feature for a specific e-mail send out only and not having to result to turning the feature off completely?

The only way I can see is to enable the "unsubscribe me" and delete the footer code in the control panel. On your emails you want to use the Unsubscribe feature, include the following in your message.
%unsubscribe_url%
(link to unsubscribe recipient from all messages sent by given domain)
%tag_unsubscribe_url%
(link to unsubscribe from all tags provided in the message)
%mailing_list_unsubscribe_url%
(link to unsubscribe from future messages sent to a mailing list)
I know that isn't the most simple method, but would solve your issue.

The best way to achieve this is to take advantage of the modularity of Mailgun when it comes to adding domains.
Given your example, if you own say, domain.com you can create a subdomain news.domain.com or any similar subdomain name.
Disable the footer for that subdomain here:
https://mailgun.com/cp/unsubscribes?domain=news.domain.com
Once that's done send an email using that subdomain rather than your full-domain.
Advantages are that you keep control of your footer without any complicated code related steps and the fact that emails are still coming from your domain thus all the deliverability metrics linked to your domain and IP remain the same.
For example from the commandline
curl -s --user 'api:key-apikeyapikey' \
https://api.mailgun.net/v2/NEWS.domain.com/messages \
-F from='me#myself.com' \
-F to=some#customer.com \
-F subject='Hello' \
-F text='Testing some Mailgun awesomness!'

Related

SES Custom MAIL FROM subdomain verification

I am setting up the custom MAIL FROM domain based on this link: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/mail-from.html
I have primary domain verified and I have added the MX record to the DNS settings, which I can see on the mxtoolbox.com. However, the Custom MAIL FROM domain is still in the status of "pending verification".
Does amazon check it in batch(maybe once per hour) or those changes should be visible immediately? Or is there any place where there could be misconfiguration from my side, when I see the MX record visible? What can I do to successfully configure the Custom MAIL FROM domain?
Dig command has been verified with the MX record to the amazonses.
Spf record allow specifically designed ip's, without the -all option. Could that be the reason?
If anyone is struggling with the same problem, this few things help:
1) Remove Your custom MAIL FROM domain from SES
2) Add it one more time
That was the steps, that support gave us which also worked.
Simple "Turn off - Turn on" and everything works :)

Unable to send mail via Mailgun over api or smtp

I have setup a new account and not verified my domain. I would like to test and confirm mail-send before proceeding with verification and adding payment information.
I have tried curl using the sandbox method and api key (including smtp). I have also tried to use my domain using the top account mail-address as recipient. But each time the send command (both curl and smtp) I get "Mailgun Magnificent API" response - but no mail is delivered. So far the Mailgun API does not look so Magnificent... I have gone through the documentation multiple times and cannot find what I might be doing wrong..
Any help is much appreciated.
Faced the same issue while sending emails via api by php curl. I solved it by changing API Base URL https://api.mailgun.net/v3/YOUR_DOMAIN_NAME to https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages.
It's because their api is not only for sending.
Hope this helps.
For anyone else trying to figure out what "Mailgun Magnificent API" means in a Mailgun HTTP 200-OK API response, it occurs when posting to https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/some/api/endpoint when /some/api/endpoint is not a valid Mailgun API endpoint.
If you are using a client library, there's probably a mistake in your Mailgun sender domain setting. Say you've verified the domain mg.example.com with Mailgun. Examples that can result in "Mailgun Magnificent API" (the exact setting name depends on the library):
MAILGUN_DOMAIN = mg.example.com # comment—this is a common mistake in dotenv files, which don't usually support inline comments; move the # comment to its own line
MAILGUN_DOMAIN = mg.example.com/mysite—get rid of the /mysite part
If you are posting directly to the Mailgun API (or developing a client library), there are some additional ways you might get "Mailgun Magnificent API":
Omitting the API endpoint: https://api.mailgun.net/v3/mg.example.com (as noted in another response)
Misspelling the endpoint: https://api.mailgun.net/v3/mg.example.com/massages (that should be messages with an e)
Including a # or ? after your domain: https://api.mailgun.net/v3/mg.example.com #/messages (see the note above about comments in config files)
Including an extra path after your domain: https://api.mailgun.net/v3/mg.example.com/route/to/my/app/messages
Note that you won't see "Mailgun Magnificent API" if YOUR_DOMAIN_NAME is not a valid sending domain you've registered with Mailgun. (In that case, Mailgun instead responds 404-Not Found).
The mailgun guide shows you to use https://api.mailgun.net/v3/YOUR_DOMAIN as YOUR_DOMAIN_NAME as in the snippet below and this was the problem.
If you're using mailgun-js, you simply need to have YOUR_DOMAIN as YOUR_DOMAIN_NAME.
No need for the https://api.mailgun.net/v3 part
const API_KEY = 'YOUR_API_KEY';
const DOMAIN = 'YOUR_DOMAIN_NAME';
const mailgun = require('mailgun-js')({apiKey: API_KEY, domain: DOMAIN});
const data = {
from: 'Excited User <me#samples.mailgun.org>',
to: 'foo#example.com, bar#example.com',
subject: 'Hello',
text: 'Testing some Mailgun awesomeness!'
};
mailgun.messages().send(data, (error, body) => {
console.log(body);
});
The problem for me was not including my domain name in the url and trying to type everything onto a single line. Strictly following their online example. Typing a backslash will bring your cursor to a new line.
$ curl -s --user 'api:key-xxx' \
https://api.mailgun.net/v3/your_domain/messages \
-F from='User <user#sample.mailgun.org>' \
-F to='xxx#gmail.com' \
-F subject='Hello' \
-F text='Testing some mailgun!'
Response
{
"id": "<xxx.x.xxx#your_domain>",
"message": "Queued. Thank you."
}
Including an slash "/" after messages url part at the end causes this failure too.
For example if you are using a library like Refit for c#, ensure your service interface be declared like this (see the Post attribute):
public interface IMailgunService
{
[Post("")]
Task<JsonDocument> SendEmailAsync([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> data);
}

Getting the original sender when forwarding emails

How can I get the address of the original sender, when an email has been forwarded to Mailgun?
The chain of events looks like this:
originalSender sends message to someUser
someUser forwards message to Mailgun
Mailgun POSTs a parsed message to my server
Put in another way:
orignalSender (send)-> someUser (forward)-> mailgun (POST)-> myserver
The best I could get is doing a regex on the "body-plain" property.
The problem is that email clients do send this differently. Here are two examples.
Forwarding from GMail (I added the ...):
body-plain: "---------- Forwarded message ----------\r\nFrom: Kalle Kalleson <kalle.kalleson#mail.com>\r\nDate: 2014-02-13\r\n ..."
Forwarding from Apple's Mail (I added the ...):
body-plain: "(...)Begin forwarded message:\r\n\r\n> From: Kalle Kalleson <kalle.kalleson#mail.com>\r\n> Subject: New color printer\r\n> Date: 11 February, 2014 15:47:19 GMT+1\r\n>
There must be a better way of doing this, right?
Thanks in advance!
I've just been in contact with Mailgun support and they could not offer a different strategy.
That is, parsing the body myself, taking in account the differences between email clients.
Lame I would say, :-(
Here you can vote up the feature request.
http://mailgun.uservoice.com/forums/156243-general/suggestions/5528656-extract-the-original-sender-of-a-forwarded-email
Has anyone come up with a better answer?
Perhaps I am missing what you are looking for, but when Mailgun POSTs to your server, you should be able to pull the From field from the POST data. I'm using a node.js app to parse my messages, however, in PHP it would look something like:
<?php
$from = $_POST["From"];
echo "This message is from: ".$from;
?>
I apologize if I'm missing what you're asking.
Using a regular expression should do the trick in either case.
Try:
/(From:.*>)/g
Not possible to take original sender of an email throw any mail services.
So, we implemented regex and take the first occurence of the match from mail html body.
Regex.Match only returns first match so used this with below regex.
From:\s(.*?)>
https://regex101.com/r/1pUpPU/1

How to pipe an email into Django?

I'm part of a two-man business selling LED glow toys and one aspect of this is handling support requests. I have a server running exim4 and DJango and have email working so that if a user sends an email to support#myhost.com I'm able to pick up the email and respond.
I'd like to develop something a bit tidier to keep track of the email chain for a particular support request.
To do this, I was thinking of piping the output of my email using a rule in my support email's filter:
pipe /usr/bin/email_to_django_script
What I'm unsure of is how best to go about the last step to actually turning the email content into something DJango can process.
What's the best method to do this? Would a script using curl -d be a sensible option or are there better / less convoluted ways?
You can pipe the output of the email server into a management command. As an example, I have a file /inquiries/management/commands/proc_email.py. I have a single Command class, and the handle() method gets most of the email from the environment, and the body of the email from STDIN:
from_email = strip_tags(os.environ.get('SENDER', None))
to_email = strip_tags(os.environ.get('RECIPIENT', None))
emailMessage = email.message_from_string(''.join(sys.stdin.readlines()))
There is other code in there, but that is how I get the important bits out of it. You can then pipe this into your ORM objects, and access it from the website at some later time.
This is then accessed through /path/to/project/manage.py proc_email.
Depending on your email server, you can also use plus addressing to insure replies come back to the same address. For example, I have my Reply-To headers set to inquiry+12345#whatever.com. The mail server (postfix) then dumps this into the environment under EXTENSION. If no number is supplied, I simply create a new Inquiry, instead of attaching to an existing one.
Not exactly a pure Django solution but I would recommend taking a look at Lamson Project. It's an email server written in Python that you can use to build email applications like what you are describing. I can also integrate with the Django ORM. http://lamsonproject.org/docs/hooking_into_django.html

Django Email backend (keeps sending email from incorrect "sender")

I have several instances in my project where I attempt to send an email within a Django view.
I want to be able to hardcode the email sender within the view. When I try to do so, though, it continues to send the emails from the default account specified in my settings file.
Here is an example:
if testform.is_valid():
beta=testform.save()
subject="Hi Beta Tester"
sender="correct#email.com"
recipient=[testform.cleaned_data['email']]
text=loader.get_template('registration/beta_email.txt')
html=loader.get_template('registration/beta_email.html')
site_name='mysite'
d=Context({'site_name':site_name})
text_content=text.render(d)
html_content=html.render(d)
#This sends two mail versions, plain text and html
msg=EmailMultiAlternatives(subject, text_content, sender, recipient)
msg.attach_alternative(html_content, "text/html")
msg.send()
return HttpResponseRedirect('/splash/')
I thought that I could send specify the sender argument explicitly here. And, yet, when I test it, the email is being sent from the address listed in my settings file, configured as the following:
EMAIL_USE_TLS=True
EMAIL_HOST='smtp.gmail.com'
EMAIL_HOST_USER='wrong#email.com'
EMAIL_HOST_PASSWORD='private'
DEFAULT_FROM_EMAIL='wrong#email.com'
Do I just have to remove the DEFAULT_FROM_EMAIL constant to make it work? I tried doing so and it seems to be working but I'm confused. In the Django documentation, it suggests that setting sender in the view should override the DEFAULT.
I've finally figured out the issue here. Unfortunately, gmail rewrites the from and the
envelope on authenticated smtp.
If you want to get around that, you have to use a third party mail server (which doesn't act like such a prissy) and then send mail to gmail users.
For the sender e-mail try putting it in < > and you can add a name:
sender = "Formal Name <correct#email.com>"
that is exactly the syntax I have in my e-mail sending view and it works.
There really shouldn't be a reason that adding the name to it would change how it's sending, but it may be worth trying and perhaps you want an easily readable name anyway.