5

I'm trying to setup ZOHO mail with Nodemailer. The mail is configured correctly and I'm using following code to send the mail:

var transporter = nodemailer.createTransport({
    host: 'smtp.zoho.eu',
    port: 465,
    secure: true, //ssl
    auth: {
            user:'info@myaddress.be',
            pass:'supersecretpassword'
    }
});


sendMail = function(req,res) {


var data = req.body;

transporter.sendMail({
    from: data.contactEmail,
    to: 'info@myaddress.be',
    subject: data.contactSubject,
    text: data.contactMsg
});

res.json(data);

};

I contacted official support but no response so far. Maybe someone here has experience with it. The problem is that when using these settings I get a message that relaying is disallowed for the address in variable 'data.contactEmail'. When I change the from e-mail also to info@myaddress.be I do receive the e-mail but of course I do not know who sent it and can't reply to it.

Anyone who knows how to make the 'from' address work with unknown addresses? Like john@gmail.com ?

Nicholas
  • 1,189
  • 4
  • 20
  • 40

2 Answers2

2

Solution :

You should make an email account for your server : bot@myaddress.be

When you are going to relay the mail craft a custom MAILBODY containing the subject and message

var MAILBODY ='\n[suject]:\n'+data.contactSubject+'\n\n[msg]:\n'+data.contactMsg;

So you will be sending the original contactEmail as the subject of the mail and using the mail's text (body) to se the message subject and the message content.

transporter.sendMail({
    from: 'bot@myaddress.be',
    to: 'info@myaddress.be',
    subject: data.contactEmail,
    text: MAILBODY
});

Reason of Solution :

Example bot account will be able of sending the email to yourself with all the details you really need. (because you control that email account / your domain)

EMX
  • 6,066
  • 1
  • 25
  • 32
  • That could indeed be a solution. But you won't be able to press the 'Reply' button in your mail client then I think. You would have to copy the reply address from the mail body then. Or am I wrong? – Nicholas Aug 20 '17 at 19:20
  • Yes the reply button wont work in that way, if you want a reply button then you will have to build your own backend for automating that reply to the original mail (in other words make a small email client and instead of using the bot account store the messages in the db) – EMX Aug 20 '17 at 21:34
  • Ok, for now I used the 'bot' solution so I'll mark your solution as the answer. But I don't completely understand your idea for the reply button. Do you maybe have a tutorial with an example or something? – Nicholas Aug 20 '17 at 21:45
0

The credentials you are providing are for your OWN account and you are trying to send an email FROM an unknown account. This might only be possible if you had the credentials for the unknown account (given that they have allowed open access to other clients/apps). You simply can not send an email on behalf of an account you do not have credentials for.

Fahad Farooq
  • 449
  • 5
  • 11