Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemailer with ZOHO mail

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:'[email protected]',
            pass:'supersecretpassword'
    }
});


sendMail = function(req,res) {


var data = req.body;

transporter.sendMail({
    from: data.contactEmail,
    to: '[email protected]',
    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 [email protected] 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 [email protected] ?

like image 366
Nicholas Avatar asked Oct 29 '22 03:10

Nicholas


1 Answers

Solution :

You should make an email account for your server : [email protected]

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: '[email protected]',
    to: '[email protected]',
    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)

like image 114
EMX Avatar answered Nov 15 '22 10:11

EMX