How to strip attachments from inbound mails in Mailgun before POSTing? - mailgun

Is it possible for Mailgun to POST only the non-attachment part of emails to my API, to prevent big attachments affecting the performance of the app?

Mailgun can host the attachments for you with the inbound functionality.
You can use the Events API command store(notify=”http://myapp/post”) specifying as shown the notify option, which will send a webhook to your application with a URL on message arrival.
One of the headers sent with through webhook will look something like: ["[{\"url\": \"https://api.mailgun.net/v2/domains/YOURDOMAIN/messages/ALARGESTRINGOFCHARACTERS/attachments/0\", \"content-type\": \"META/META\", \"name\": \"MYFILE.EXT\", \"size\": 74622}]"]
Then you can retrieve it and delete the stored message.
Keep in mind that stored messages are kept only for so long so you should process attachments rapidly.
This is one of the options of the routes functionality that Mailgun gives you.
Personally I love it ! Let me know if something is unclear i can dig into more details!
Best,

I am getting mail on the Mailgun which I am routing to my local server and their. I am parsing the JSON but problem is coming in case of attachments. In attachment json, it is showing the path of temporary file on mailgun server. I need to download the attachment and store it on my local machine.
My question is how to retrieve that attachment. Do we have any API for that?

To access the data from the link, you will need to specify credentials as your get parameters. The user is 'api' and the password is your mailgun's private key
Please refer to this answer that I've given here

Related

How to setup an email address for sending only?

My main goal is to setup an email address for my server to use for sending emails only.
I did some research, and it looked like Amazon Simple Email Server and/or Amazon Workmail could provide me with what I needed. I've gotten as far as setting up SES and Workmail so that I can set my server to be able to send emails. However, I saw that once the Workmail inbox is full (50GB), the account would be unable to send emails. Given that this is going to be used by the server and not a human, I didn't want the inbox to get filled with auto replies, spam, or failed to send messages, and then be unable to send emails. So, I went looking for a way to either:
A) prevent emails from being received and stored in the inbox
B) a rule I could setup to delete anything that didn't match the company domain
C) be able to read the inbox and delete email messages using the AWS CLI, and I'd setup my own script to manage how and what was deleted when
So far I haven't had any luck.
Again, I'm not particular how I achieve the goal, but I do preferably need to find a way to have an email address for a server to use exclusively for sending messages. I worry that if I leave it to employees to remember to login and clear the inbox, someone will forget, and then the server will stop sending emails.
Any direction or advice would be greatly appreciated.
I'm not well versed in email protocols; could I setup the address to return a bounce back always, and that would prevent it from receiving emails into it's inbox?
How are you generating these emails? If you are generating them programmatically (via an app/script), you may not need to set up a server. If you just route the outgoing mail through your app to SNS, the emails will be valid, however, there will be no "inbox" for incoming mail and they will just be dumped. This way you don't have to actually worry about an inbox getting full as it will just drop anything coming in.
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email.html
In order to receive emails though SNS, you have to go through the setup linked above, but if you do not set this up, then emails will just bounce. At least, that is how I have been doing it.

Send email with custom from with amazon ses for several domains

How can I accomplish to send email in Amazon SES with a custom email from for several domains.
For example, I have an application that is used by several clients, and we have a module to send emails. When we send an email it goes with the "amazonses.com domain", but what I want to accomplish is a custom from email for each client, each one has a different domain.
The process for doing this is entirely specific to the current SES configuration steps so its better I provide a link thats regularly updated.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/mail-from-set.html
The short summary is that you can do this by choosing a FROM option for the emails you are sending from.
Programmatically Setting From
The link above points how how to use the API to programmatically change the FROM value. The link below is directly to the API call for setting from but to accomplish it you'd still need to follow the manual tutorial then replace its steps with equivalent API Calls.
http://docs.aws.amazon.com/ses/latest/APIReference/API_SetIdentityMailFromDomain.html

"Read" Emails with Django

Currently sending emails with Django, and was wondering if there was any way to periodically check my inbox with Django (or ideally somehow alert the server upon receipt of a new email), and have Django extract the message and save it in the database.
You could use an email service such as SendMail or Mandrill (latter definitely has free accounts, former may have).
Each of these services provide inbound email support via webhooks. You provide them an endpoint to hit (make sure to use HTTPS) and when they receive an email to an address you have registered they will send the data via HTTP POST to you.
It is then just a simple case of storing this data to the database. There are a number of 3rd party packages that can help you with this:
http://djrill.readthedocs.org/en/v1.4/usage/webhooks/
https://github.com/yunojuno/django-inbound-email
https://github.com/jpadilla/mandrill-inbound-python
https://github.com/michaelhelmick/python-mailsnake
Although it's rather simple to roll your own should need be.

How would I know that email has been sent or not via SendGrid in Django

I am working on django and sending emails to multiple users at once. in the given scenario it only tells me that if it has sent or not.
I want to display the report of same page that how many emails has sent to user successfully and how many not. more if i want to get details why email has failed to sent.
How would i do such things via SENDGRID APIs.
There are two options that I know of:
Connect to SendGrid Event Webhooks and start parsing events for every email to flag ones that were not sent. I believe you can configure SendGrid to only send certain events, so if you're interested in bounces you don't need to worry about handling all events.
The second option is to use a service like sendwithus which will connect to your SendGrid account on your behalf and track all bounces/opens/clicks for you and provide a simpler API/UI to view the data. I believe they do this via SendGrid's webhooks, so it's effectively the same solution but written for you.
Happy to elaborate on either, I've used both before.

Get and Send messages through amazon api

My company is working with the amazon MWS api, and we are receiving a lot of messages from the customers about their orders.
Is there any way to get these messages using the web services and reply to them?
As #joshubrown pointed out correctly, there currently is no API to get customer messages or send replies. You can, however set up a separate mail account for that purpose, which (depending on your own server architecture) gives you a whole set of protocols like POP3, IMAP, SMTP or even MAPI. Regular emails sent to the "scrambled" customer email addresses will be relayed to the consumer and will shown up as replies in your Seller Central.
No, there isn't a public API for that.
How I was planning to do this (in the absence of an API) was to set up the email account (that would receive the emails from customers) such that it pipes the email content into a script. The script would then write the content to the database (or do whatever you want with it).
I'm using qmail for mail, and if you edit the .qmail file within an email account's folder you can set where to pipe the email content eg
| php /pathtoscript/emailHandlingScript.php
Other email systems will have a different syntax for this.
Then in your PHP code (if you're using PHP), you can grab the content from the stdin stream:
$fh = fopen('php://stdin')
I'll probably use PHP's mailparse functions (eg mailparse_msg_parse_file, mailparse_msg_get_part etc) to properly extract the data from the stream.
As #Hazzit points out, when you reply to the anonymised email address (eg qwugwquigduwqgiqwdgiuwqdg#amazon.co.uk), Amazon will pass it on to the customer.
I created users on my account, redirected mails and made a script to read and reply.