Forwarding emails via the Mailgun API: possible? - email

I have a use case for an email flow that looks something like this:
1) User sends an email to a specified address
2) Service receives the email and pings a webhook with the email in json format
3) My webhook/backend runs a quick check on the sender's email address and either:
4a) Creates an email and sends it as a reply to the original user, or
4b) Forwards the original email to another destination (it's important that the forward email retains the original senders address/reply-to etc.
Ok, I can easily get as far as 4a) using one of a few services (PostmarkApp, Mailgun, etc), but I'm struggling with 4b) - forwarding using an API.
The closest I can get is to receive the email into my Mailgun account and set a route that both stores it, and pings a webhook URL.
It then seems like I should be able to instruct Mailgun to forward the stored email to the final destination - but I just can't figure it out.
Anyone been here before?
I'm asking here before trying Mailgun support.
Thanks.

Related

How to track activity for a do-not-reply email in the SendGrid account

We are new in Sendgrid and we want to use it to track our system email but it did not seems to work with the new API key. The system are using do-not-reply email to track on the user activity.Can I know how can we authenticate this email to keep track on the activity in the SendGrid?
If you want to receive emails with SendGrid you need to do a few things. Here's an overview of what you'll need to do:
Get a domain that you want to receive emails on.
Set up MX records for a hostname on that domain to receive emails via SendGrid. Note that the hostname you choose (it can be a subdomain) should be used exclusively to parse your incoming email. The MX record should point to mx.sendgrid.net with a priority of 10.
Set up the webhook URL. In your SendGrid dashboard, click settings, then Inbound Parse and then Add Host & URL
Specify the receiving domain or hostname and a URL that will receive the webhooks when an email is received.
Save
The process of setting up the Inbound Parse Webhook is documented in detail here.
What you do with the webhook from then is up to you.

Mail Forwarder with static sender address - the chicken-egg-problem

this is a pretty specific case, but it drives me crazy...
We recently migrated our email service to google workspace. We do have an invoice#mydomain.com address which earlier was configured to forward emails to someinbox#datev.com. someinbox is a mail upload feature for tax related invoices of our company. The problem started when i was trying to set up the mail filter in Gmail.
All emails with an attachment should be forwarded to someinbox#datev.com. To forward emails with Gmail, google needs to verify that I am allowed to forward to that specific address. It therefore now sends a confirmation email with a link to that address. that email is being sent by eg. noreply-forwarding#google.com, which is being rejected (550 5.7.1 Security policy violation: sender address not authorized). The problem is, datev only accepts emails from "verified sender addresses". It does that verification by also sending an email verification to that "verified sender address". Which in my case now becomes the noreply-forwarding#google.com, which I obviously not maintain and therefore i am unable to verify that address.
So I am unable to add the forwarding email address in Gmail, because of the sender google uses to verify the forwarding address.
We use google workspace, so I am able to use the pretty cool routing feature of Gmail. First I created an email-alias called datev#mydomain.com. I then setup a rule which simply changes the envelope-sender to someinbox#datev.com if the envelope-sender is datev#mydomain.com. that part works. If I send an email from the invoice#mydomain.com to datev#mydomain.com it changes datev#mydomain.com to someinbox#datev.com.
The next problem was, every forwarding (which the Gmail filter was doing) works by sending the same email to someinbox#datev.com while keeping the original sender. That also happened when I tried to do the same workaround by creating a new email forwarder (or even a mailbox) on a different domain without google workspace. I also tried it using posteo. The original sender is being used as the sender address and therefore datev rejects it. It wouldn't be possible to register all sender address as we get a lot of invoices from business partners.
Does anybody know or see a way of doing this? Aren't there any secure email forwarder which replace the sender address to the one of the forwarder instead of keeping the original one? I know, this is in most cases a pretty nice feature as you can see who the email originally sent, in my case it makes me nuts.

How does an SMTP server resolve ambiguity?

Suppose I own an email 'demo#gmail.com'. Now, I create a new Microsoft account using my existing email. Thus I get another email 'demo#gmail.com', but this one is served by Microsoft.
So the situation is: one email and two providers.
If I send a hello email to 'demo#gmail.com' using my personal SMTP server, to which of the above will it send: will it send to the one hosted by Microsoft or the one hosted by Google?
How does it solve such an ambiguity? What are the factors that influence this?
This is a very common problem because many providers are giving us an option to create a new account using our existing email.
My observations:
I saw the emails inside the inboxes of both the services. I found that they had completely different emails.
There was no email which was common to both the inboxes. So there must be some mechanism to deal with it.
Let us look at the problem the other way round: If I had an email 'demo#outlook.com' initially and I created a new Google Account with this email address, then:
An email sent to this email address from another gmail account goes to the Google's server. An email sent to this email address from an Outlook also goes to the Google's servers.
There are two different ways of looking up an email. The 'normal' way:
You send an email to an server, in this example gmail.com.
Your mail delivery agent looks for mx record of gmail.comand send it to the ip-address of gmail.com.
If an email is delivered locally by the domain outlook.com it perhaps doesn't lookup the mx record, but lookups in a local database if the email-address exist there, and sends it to the ip-address of the outlook.com.
I think in the inbox of outlook.com are only microsoft emails.
More details can be found at https://www.socketlabs.com/blog/smtp-email-delivery/

Allow replying-to dynamic local-part of address sent by sendgrid

I have user in my system who can send emails through my API. The API uses SendGrid to send the emails with their username as the sender + reply-to address.
user_1#mydomain.com
user_2#mydomain.com
user_3#mydomain.com
What I would like to do is allow people to reply to these emails but I'm unsure how to do this.
Obviously if I try to reply as is - I get an error saying the email couldn't be delivered.
Is there something to do with SendGrid which can handle previously unseen addresses #mydomain.com or do I need to do something to set them up initially in the first place?
The solution was to use incoming web-hooks.

ID variable in cPanel email forward

I am building an app that incorporates Postmark App's Incoming Email capability to keep a threaded list of replies to an email. Their documentation suggests adding the post ID to the reply-to address - for example reply+POSTID#domain.com. However, when I attempt to use this method with cPanel, the emails are bounced back.
I have reply#domain.com set up, without adding the post ID the email is forwarded to the Postmark App inbox address, adding the ID breaks it. Is there any way to do this in a WHM/cPanel environment? It is a VPS account so I have full access if there is another way to tackle this.
Are the messages bounced back from Postmark or is it a cpanel error? I can probably help you out there! Do you have an MX record setup for Inbound via http://developer.postmarkapp.com/developer-inbound-mx.html ? Once you have that going Postmark will accept messages from any address on that domain and parse off the addresses with + chars in them. Are we sure cpanel can handle email addresses with special characters?