I have a utility which runs at certain intervals. My customer now wishes for it to send an email when the task is completed.

They want to be able to control the email address, meaning, they want to be able to enter their SMTP details.

This is quite a trivial task, but, the storage of the password is not.

When customers log onto a website, I hash it, using a salt but that's simply because I don't need to use the password, however, for email, I will need to send the email, probably in plain text.

I accept that sending the password over the network to the SMTP server in plain text is a risk, but that is not the question.

I'm more concerned about some one finding the password details in plain text within a text file or a field of a database. I need to offer at least some layer of defense.

It is just as simple as encrypting the password as such I can decrypt it?

  • 2
    Encrypting the password is slightly better than storing it in plain, but not much, since you still need to store the key somewhere. Commented Jun 29, 2015 at 9:48
  • "and a 'random' number" what do you mean by that? Usually the salt is the random number. Commented Jun 29, 2015 at 9:50
  • Sorry, updated post. Yes, I understand the key has to be some where and this is the issue but, I'm not sure if there is another option (without a design change) @CodesInChaos? Commented Jun 29, 2015 at 9:54
  • 3
    Store your 2 way encryption key somewhere other than the database (server file system perhaps) and store the encrypted password in the database. This removes the single point of failure of the database being compromised (this still isn't great but if the password has to be retrievable the best you can do is increase the number of points that have to be compromised Commented Jun 29, 2015 at 10:34
  • Why not just have your app email to an alias that the customer controls? The customer can edit the alias as desired. Commented Jun 29, 2015 at 13:40

2 Answers 2


Assuming you own SMTP servers,

  1. I would set up firewalled local instances of Node.js or something like that on the same machines where SMTP is located and store passwords encrypted on those machines. Setup proper local access permissions on those servers.
  2. Then expose those instances for certain requests to certain IPs just to cover your main service.

In this case, your passwords are protected somewhat more because they are not accessible from outside. You don't need to store them in your main database.

UPDATE: With this architecture you are abstracting the communication to SMTP servers to Node.js instances. So you main application can really connect to anything going forward if you maintain the contracts.

  • What if it's using gmail servers? Commented Jun 29, 2015 at 17:44
  • Then I have to ask you - why are you using Gmail for programatic access? Why are you accessing someone else's email? For Gmail, use Google API to retrieve data.
    – Alexus
    Commented Jun 29, 2015 at 17:47

Consider using built-in password vaults. For example, Windows 8 has a credential manager, Windows 7 has the Data Protection API, Apple has keychain, etc.

Note that such features primarily protect against password theft by a user without different credentials than the owner (e.g., on multi-user systems).

As you haven't explained your threat model, I'm unsure if this is sufficient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.