How to hide SMTP Auth user mail id in Nodemaile - javascript

I am using nodemailer in my project . (sorry for
My english is not good )
var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "agodatest#gmail.com",
pass: "pwd"
}
});
smtpTransport.sendMail({
from: "James andrison <james#andr.com>", // sender address
to: "user2 surname<receiver#receiver.com>", // comma separated list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world ✔" // plaintext body
}, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
});
In the Above code When I receive mail. I can see Sender name with auth.user email id in the mail but cannot see Sender email id.
I got output like this --> James andrison ;
So can you tell me how to hide SMTP / Auth email id ?
Thankx in advance .

Related

Possible issue when sending email with SMTP.js

I am using smtp.js to send mails to my email id whose credentials i made using smtp.js.I made a contact form where i want the user to enter his info and email and that should be sent to my email.So according to this logic, my mail should be in To property and sender's mail should be in the From property.However, when i run the code, it throws an error as
"Mailbox name not allowed. The server response was: Envelope FROM 'sendername#gmail.com' email address not allowed.".
If not possible,can u tell me some other alternative using js.Thanks
Code:
function sendmail()
{
var name = $('#name').val();
var email = $('#email').val();
var phone = $('#phone').val();
var address = $('#address').val();
var postal = $('#postal').val();
console.log(typeof(email))
// var body = $('#body').val();
var Body='Subject: '+"Estimated Quote"+'<br>Name: '+name+'<br>Email: '+email+'<br>Phone: '+phone+'<br>Address: '+address+'<br>Postal Code: '+postal+'<br>Quote exl VAT: '+vat_excl+'<br>Quote incl VAT: '+vat_incl;
//console.log(name, phone, email, message);
Email.send({
SecureToken:"2d019ac3-046b-4c4f-94e2-f4f3bf08fb1f",
To: 'receivermail#gmail.com',
From: email,
Subject: "New mail from "+name,
Body: Body
}).then(
message =>{
console.log (message);
if(message=='OK'){
alert('Thanks for submitting details.We will contact you soon.');
}
else{
console.error (message);
alert('Error submitting form.')
}
I don't know which library are you using to stablish the SMTP connection, but first of all make sure that the SMTP sever accepts all the domains that you're requiring.
I'd suggest you to use nodemailer which is fairly easy to use.
Example:
// CONFIG SETUP
import { createTransport } from 'nodemailer';
const Transporter = createTransport({
host: process.env.SMTP_HOST || 'localhost',
port: Number(process.env.SMTP_PORT) || 25,
secure: false,
tls: { rejectUnauthorized: false }, // THIS WILL BE ACCORDING TO YOUR SMTP CONFIG
});
// EXAMPLE OF USAGE
const info = Transporter.sendMail({
from: 'sender#test.com',
to: 'to#test.com',
subject: 'TEST',
text: 'TEST',
});

Setting nodemailer from address using request data

When nodemailer sends out an email from a contact form, it goes to an admin, who then responds to the email address found in req.body.email
I'd like to set the reply-to address as this value, so that the admin can simply hit reply to send a reply with the message data, without having to copy paste the email into the 'to' field. Here's what I've got:
Send email util
const sendEmail = async options => {
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
auth: {
user: process.env.SMTP_EMAIL,
pass: process.env.SMTP_PASSWORD
}
});
// send mail with defined transport object
let message = {
// from: `${options.fromName} <${process.env.FROM_EMAIL}>`,
from: `${options.fromName} <${options.fromEmail}>`,
to: options.email,
subject: options.subject,
text: options.message,
html: options.body
};
const info = await transporter.sendMail(message);
console.log('Message sent: %s', info.messageId);
};
module.exports = sendEmail;
Send email function
try {
await sendEmail({
fromName: emailBody.name,
fromEmail: emailBody.email,
email: 'admin#email.com',
subject: `${emailBody.name} sent a message!`,
body: emailBodyText
});
} catch (err) {
console.log(err);
return next(new ErrorResponse('Email could not be sent', 500));
}
Here's what I get:
response: '553 5.7.1 <user#gmail.com>: Sender address rejected: not owned by user admin#email.com'
I get that admin#email.com cannot send email from user#gmail.com, but I'd like to have that ux of being able to simply hit reply and have the email directed to the user. Is there a good way to make it work like this?

How to change sender name different form authenticated email?

var nodemailer = require('nodemailer');
// Not the movie transporter!
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '*****#gmail.com', // Your email id
pass: '*******' // Your password
}
});
var mailOptions = {
from: varfrom_name, // sender address
to: varto, // list of receivers
subject: varsubject, // Subject line
text: vartext, // plaintext body
html: varhtml // html body
};
console.log(mailOptions);
// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
return console.log(error);
}else{
return console.log(info);
}
});
I want different sender address from the authenticated one ?
Suppose I authenticated data with abc#gmail.com, but I want to send the mail from xyz#gmail.com to def#gmail.com.
How to do that in node-mailer ?
// Using send mail npm module
var sendmail = require('sendmail')({silent: true})
sendmail({
from: ' xyz#gmail.com',
to: 'def#gmail.comh',
subject: 'MailComposer sendmail',
html: 'Mail of test sendmail ',
attachments: [
]
}, function (err, reply) {
console.log(err && err.stack)
console.dir(reply)
})
But the mails coming in the span box and the mails that we are sending is won't showing in the sent mail of sender mail address ?
I hope i will able to elaborate my question
I don't think you can. Gmail does not allow the change of the sender address.
However, you can look for another service, like postmark, sendgrid, or create your own smtp server.

Send email is not sending email when used nodemailer with protractor

No message is displayed for the error but also for the message for success is also not displayed. Also no email is recieved.
This is the code i had in the config file of protractor. Here there is no error response for the email but also there is no successful message also and no email is received.
this is in the config file
onComplete: function () {
creating reusable transport method (opens pool of SMTP connections)
var smtpTransport = nodemailer.createTransport("SMTP", {
host: "smtp.company.com",
port: "110",
auth: {
user: "anuvrat.singh#companyemail.com",
pass: "XXXX#2015"
}
});
setup the email data
var mailOptions = {
from: "anuvrat.singh#Company.com", // sender address
to: "anuvrat.singh#Company.com",
subject: "Hello ✔", // Subject line
text: "Hello world ✔", // plaintext body
html: "<b>Hello world ✔</b>" // html body
}
send mail with defined transport object
smtpTransport.sendMail(mailOptions, function (error, response) {
if there is an error it will display other wise it will send the message
if (error) {
console.log(error);
} else {
console.log("Message sent: " + response.message);
}
shut down the connection pool, no more messages
smtpTransport.close();
});
}

Cannot read property 'createTransport' of undefined

I am testing sending email with meteor js and nodemailer plugin:
meteor add mrt:meteor-nodemailer
when the page loaded, i saw error in the console of the navigator :
Cannot read property 'createTransport' of undefined.
so what is the problem ?
this is the code :
///////////////////////////////////////////
var nodemailer = Nodemailer;
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "myname#gmail.com",
pass: "mypass"
}
});
var emailNodemailer = function() {
// setup e-mail data with unicode symbols
var mailOptions = {
from: "Sender Name ✔ ", // sender address
to: "someone#yahoo.fr", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world ✔", // plaintext body
html: "Hello world ✔" // html body
};
// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
// if you don't want to use this transport object anymore, uncomment following line
//smtpTransport.close(); // shut down the connection pool, no more messages
});
};
///////////////
This worked for me import * as nodemailer from 'nodemailer';

Categories