How to send e-mail from non-existing (autogenerated unique id) email?

ⅰ亾dé卋堺 提交于 2021-01-27 04:41:31

问题


I'm the owner of a domain, and I'm currently hosting its mail (MX) in Google Apps for Business.

I have a catch-all account, so if someone replies an e-mail to generated-unique-id@mydomain.com, I have a robot that will read that e-mail and do some processing.

Problem is: How can I send an e-mail from that sender's address? I mean: I cannot create a userid for every generated id, and if I authenticate into Google SMTP with some user, the sender is automatically filled as that user address. (I'm aware that I can use any "verified aliases" as sender (or reply to), but I also cannot create an alias for every generated id.)

In summary: I need to send emails from non-existing e-mail address. How can I do that using 3rd party existing services (I don't want to host my own SMTP server, unless there is no easier solution).

Are there any hosted mail servers that will allow me to do that?

PS: As you may guess, it's a ticket-like system that should generate an unique e-mail address for each thread. (Yes, I know that I could use Subject for the unique identifier. Is that the best solution?)


回答1:


Gmail lets you use the local part subaddress of the email address as an ad-hoc alias, e.g.

support+ticket123@mydomain.com

will be routed to support@mydomain.com, and you can use the local part/alias for filtering.

Though I haven't tried it, I suspect you can also send from support+ticket123@mydomain.com and it will be as if the email was sent from support@mydomain.com, and the From and/or Reply-To header of the email should contain the full support+ticket123@mydomain.com.




回答2:


Actually there is a way to do exactly what you are asking for without hosting your own SMTP server. This is a general outline.

1) You need to have a hosting plan with that domain name. Depending on your hosting provider and the operating system you will have either a cpanel or a plesk panel.

2) In the control panel, create an email called ticketing@example.com and forward all emails to it.

3) Write a php script that checks ticketing@example.com regularly and replies to emails using the to: address from the email headers as the source address.

4) Some email providers might mark that email as spam, however, most spam checks are based on SPF and DKIM checks more than email existence checks. To correct for the SPF, you can add the following record to your DNS records:

v=spf1 a -all

What this actually does is declare all emails sent from the your domain ip address as "permitted senders".

The problem is, since you are not going for the dedicated smtp server solution, you probably are sharing your ip address with several other domain, and in that process you will be marking email originating from their servers as trusted. Only do this if your hosting provider provides you with a dedicated ip address for your hosting.

As for the DKIM and changing the source address, you can use php-mail-signature to sign all your emails with a DKIM key and manipulate the email header. Check the example provided on the main page.

You can follow this guide on how to add DKIM and SPF records

It should be noted that this is to just an answer to your question on whether it can be done or not. However, I do not personally believe it is the right solution. It is a cleaner solution of course to use a single address for send and receive and depend on a subject line parsing. It is also more familiar to the user than random email addresses.

To finalize, There are many free php scripts out there that will do all the ticketing system for you if you are interested in a clean made solution.



来源:https://stackoverflow.com/questions/33509943/how-to-send-e-mail-from-non-existing-autogenerated-unique-id-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!