0

I am trying to send mail by using nodemailer's mail api from express js server on microsoft azure. It's getting success in local machine but not on azure server(remote). Any idea?

 var mail = require("nodemailer").mail;
 mail({from: "from@gmail.com", // sender address
       to: "to@gmail.com", // list of receivers
       subject: "subject", // Subject line
       text: "text", // plaintext body
       html: "<b>helloworld</b>" // html body
      });

thanks, av

user3297351
  • 153
  • 3
  • 12
  • 1
    Can you give us the exception or error you are getting? As such it is hard to help you. – David Brossard May 10 '14 at 12:14
  • Does it use `sendmail` by default? I bet Azure server does not have it installed / available to install. – Eugene Kostrikov May 10 '14 at 12:43
  • Thanks for immediate reply. It didn't throw any exception. Any idea. – user3297351 May 10 '14 at 12:50
  • @Eugene Kostrikov, what is the alternative solution for this on azure? – user3297351 May 10 '14 at 13:19
  • Sorry, I am not an Azure pro. You may try to use another mail transport. – Eugene Kostrikov May 10 '14 at 20:34
  • 1
    Let's start with better describing the issue. Are you using Azure Web Sites, Azure Mobile Services, Azure Virtual Machines or Azure Cloud Service. Deriving from the type of the service describe what OS you use and its version. Then describe how exactly you configure the mail transport. According to Nodemailer documentation you try to use directly the recipients MX server which is not the best way to send e-mail and in a lot of cases it will be rejected (especially when the originating IP is from a cloud provider). – astaykov May 11 '14 at 21:09
  • @Astaykov, I am using Azure Websites. I opted sendgrid. It works fine on Azure. It's solved my problem. – user3297351 May 13 '14 at 13:03
  • surely better solution I would say! – astaykov May 13 '14 at 20:46
  • Yes. sendgrid module solved this. Thanks astaykov. – user3297351 Jun 09 '14 at 12:35
  • Please check the digital ocean related answer here https://stackoverflow.com/questions/42387451/nodemailer-connection-timeout-error – Sahil Qureshi Oct 12 '21 at 12:30

2 Answers2

3

Just in case someone else meet the same problem.

I had the same problem about running Nodemailer in Azure Website. Finally I found the problem was that I forgot put Nodemailer as a dependency in package.json. Then azure did not know it had to install Nodemailer for the hosted server.

Add "nodemailer" : "*" at the end of dependency list in package.json. Don't forget to add a "," after the last line before you add "nodemailer".

Hope it helps.

Nils
  • 91
  • 4
  • It doesn't work for me. My local node version is 0.10.20, and nodemailer is 1.3.4. It works in localhost. Based on this website: http://azure.microsoft.com/en-us/documentation/articles/nodejs-specify-node-version-azure-apps/, it should be using the latest node version in azure, so 0.12.0. I also tried to add "engines": {"node": "0.10.x"} to my package.json, but no effect either. Any help? – newman May 16 '15 at 16:54
  • 1
    Okay, I figured out what my problem is. The error was "Invalid login". The solution is to enable less secure app from google account, as mentioned in `http://stackoverflow.com/questions/19877246/nodemailer-with-gmail-and-nodejs`. Still strange why it worked in localhost, but not in azure. – newman May 16 '15 at 20:55
0

Please do changes in iisnode.yml file to call newer nodejs version as follows- nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\8.5.0\node.exe"

HamidKhan
  • 545
  • 1
  • 6
  • 9