0

I run a simple web service, and I need to securely send emails to users via PHP.

There are no mailboxes/accounts involved. It is a simple send-only function.

Without involving PGP, I have come up with the following options -

  1. Use local SMTP server and configure outgoing TLS (could still travel via plaintext across the internet?)
  2. Check user's email address. If its @gmail.com (or hotmail/outlook/yahoo) then send to Gmail/Hotmail/etc SMTP server using TLS (pretty likely to be encrypted all of the way?)
  3. Any other options?

Appreciate any help/thoughts.

  • If you only want to _send_ them secure, use a mailing service that accepts a API call over SSL. If you want to make sure they _receive_ their email securely, that's not always up to you. – Yorick de Wid Aug 24 '16 at 17:17
  • Steffen gave you a good answer. I'd like to add that you seem to be having an [XY Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem), perhaps you would benefit from telling us what you're **really** trying to accomplish. – GnP Aug 24 '16 at 17:21
  • @YorickdeWid Can you elaborate on an API call over SSL? You mean something like using Gmail/Yahoo SMTP over port 587 or 465? – MrRobot909 Aug 24 '16 at 17:32
  • @GnP +1 really appreciate Steffan's response. I'd disagree with your XY comment. It's pretty simple, I need to send "important information" to a number of email addresses securely. This email address could be random and no user information/PGP keys are known. – MrRobot909 Aug 24 '16 at 17:38
  • @MrRobot909 nope I ment a mailing service, Mailgun etc.. They allow you to call an (REST) API, and they handle all the SMTP(S)/SSL stuff for you. – Yorick de Wid Aug 24 '16 at 17:49
  • @YorickdeWid Would it be fair to say that if I use something like Mailguns SSL API, and the receiving email user has good OPSec and uses a Mail provider that supports incoming TLS, that this sending of email would likely be secure? I guess the only potentially insecure point would be the sending of mail from Mailgun to the Mail server of the recipient. – MrRobot909 Aug 24 '16 at 18:03
  • @MrRobot909 You are correct. It minimizes the change, but the same can be accomplished if you setup an SMTP server well. That obviously requires more work. – Yorick de Wid Aug 24 '16 at 18:36
  • Depending on the type of information, its source, the way it might be used, etc. there might be better ways to send it securely to the user. Maybe not even using e-mail at all. Of course, you're the one in the position to determine if this is the case, but I'd argue that at least the reasons used to rule out other options are relevant to the question. – GnP Aug 24 '16 at 19:14

1 Answers1

2

I run a simple web service, and I need to securely send emails to users via PHP.

Your exact requirements of "securely send emails" are unknown. But none of your proposals offers end to end security, i.e. depending on the path one or many parties can intercept and even modify the mail.


In detail:

SMTP has only hop-by-hop encryption, which means any MTA on the way will have the mail in clear even if TLS was used to transmit the mail to the MTA.

Also there is no guarantee that TLS is used at all because SMTP transfer starts plain (without encryption) and only gets upgraded optionally to TLS with the STARTTLS command. If this fails or if no STARTTLS is offered by the receiving MTA the mail is usually send plain text (i.e. best effort encryption). There are various ways TLS can fail (bad configuration) or can be made to fail by an attacker and there are also firewalls which simply transparently strip STARTTLS support so that they can look into the mail.

Apart from that the next hop MTA is chosen by the DNS MX record. With DNS spoofing the mail can thus be redirected/intercepted unless the sending MTA is using strict DNSSec, which it usually isn't.

Steffen Ullrich
  • 184,332
  • 29
  • 363
  • 424
  • Thanks Steffen for explaining things in detail. Can I follow up by asking - If I know a recipients email address is Gmail for example, can't I simply verify the MX record for Gmail.com and then attempt to directly establish a secure connection to this server? #Edit - I believe services like GuerrilaMail do these kind of checks, to check if TLS is available and therefore securely send mail. My knowledge isn't too good in this area. – MrRobot909 Aug 24 '16 at 17:23
  • @MrRobot909: so how do you "verify" the MX record? – Steffen Ullrich Aug 24 '16 at 17:26
  • Again I'm relatively new to this, but can't this be done using DIG, followed by nmap, followed by "$ openssl s_client -connect mx1.gmail.com:25 -starttls smtp" – MrRobot909 Aug 24 '16 at 17:34
  • @MrRobot909 that's what any MTA will do to send the message. But note how you haven't "verified" anything, you accepted a DNS response (dig) tested a port (I assume that's what the nmap was for) and connected to it. At what point did you verify you were actually talking to gmail and not some attacker? – GnP Aug 24 '16 at 19:19
  • @MrRobot909: to make sure that the DNS response you got (with dig, by the MTA, ....) is not spoofed you would need DNSSec. – Steffen Ullrich Aug 24 '16 at 19:22
  • Bear in mind that even DNSSEC can be compromised by a rogue registrar, the TLD, or the root. See https://moxie.org/blog/ssl-and-the-future-of-authenticity/. – mti2935 Apr 19 '20 at 22:00