How to use X-MC-MergeVars for handlebars - smtp

I am new to mandrill and trying to setup a mail using handlebars and SMTP. My template looks like -
<span> {{userName}}, </span> Welcome to ......
This is what my mailer.js looks like (running on node.js)
var mailer = require("mailer")
, username = "**#***.com"
, password = "*********";
mailer.send(
{host: "smtp.mandrillapp.com",
port: 25,
to: "**#gmail.com",
from: "**#gmail.com",
subject: "Mail using Mandrill!",
authentication: "login",
username: "**#**.com",
password: "********",
headers: {
"X-MC-Track": "clicks",
"X-MC-Autotext": true,
"X-MC-Template": "newsFeed",
"X-MC-MergeVars": {"userName": "Pranav"},
"X-MC-MergeLanguage": "handlebars"
}
}, function(err, result){
if(err){
console.log(err);
}
}
);
I receive mail, but userName is not replaced with the userName value passed with X-MC-MergeVars and is replaced with empty string.
Am I missing something?
Thanks,

All of your mail headers need to be strings; you're currently passing a JavaScript object for the mergevars.
Try using JSON.stringify to convert the object to a string for the header:
"X-MC-MergeVars": JSON.stringify( {"userName": "Pranav"} ),

Related

Paypal Oauth2 Axios results in circular structure

I'm trying to get a oauth token from the paypal sandbox using axios. The request looks like this:
const response = await axios.post(
'https://api-m.sandbox.paypal.com/v1/oauth2/token',
new URLSearchParams({
'grant_type': 'client_credentials'
}),
{
auth: {
username: process.env.PP_CLIENT,
password: process.env.PP_SECRET
},
headers: {
'Accept': 'application/x-www-form-urlencoded',
'Accept-Language': 'en_US'
}
}
);
console.log(`response: ${JSON.stringify(response.data)}`);
As far as I can tell this code used to work, because I used it before. However now I'm getting the error:
"Converting circular structure to JSON
--> starting at object with constructor 'ClientRequest'
| property 'socket' -> object with constructor 'TLSSocket'
--- property '_httpMessage' closes the circle"
I have confirmed that my credentials are correct by testing it with curl, which works and by copying it directly into the code. I've also tries fetch (which always yields an empty response)

cpanel email using node js nodemailer not sent mail to inbox?

while using cpanel email and nodemailer to send mail to my app user i get email sent with no errors but email don`t get in reciever inbox I using the below code
const mailOptions = {
from: "my user#gofootball.net",
to:email,
subject: 'New feedback email',
text: "hello form go sports"
};
const transporter = nodemailer.createTransport(smtpTransport({
host:'mail.gofootball.net',
port: 465 ,
secureConnection: false,
debug:true,
tls: {
rejectUnauthorized: false
},
auth: {
user: 'my user#gofootball.net',
pass: 'my user pass'
}
}));
Everything seems to be absolutely correct, except the following option:
'secureConnection: false,'
Since you are using port 465, which is the SSL SMTP port, the secureConnection should be set to true instead. This is most probably the reason for your issue. Otherwise, you might want to double-check the SMTP details that you use.

some data from nodejs is not inserting in mongodb?

So, this is the post request for my register route using express.js. I am printing the newUser object to console. It prints all the information i.e. name, collage, address, encrypted password but it didn't prints the phone to console why? and also only phone number is not inerting in mongodb database.
app.post("/register", function(req,res){
const newUser=new User({
name:req.body.fname,
phone:req.body.ffphone,
email:req.body.femail,
callege:req.body.fcallege,
password:req.body.fpassword
});
console.log(newUser);
newUser.save(function(err){
if(err){
console.log(err);
}else{
res.send("<h1>Registration done</h1>");
}
});
})
It only prints this output to console:
{
callege: 'MIT',
_id: 60450bd602c55639309f93a1,
name: 'user1',
email: 'abc#gmail.com',
password: '123456'
}
why it didn't showing phone attribute? Though I am taking right input from html form.
Check your Schema for your User model. You probably forgot to add the phone field to it.
Fields that are not included in the schema will not be inserted into the document, which could be why your phone number is not appearing.

How to trim a string in artillery that contains a "\n" char?

After successfully extracting username and password from a csv as shown in the documentation, I noticed that my username was in the following format: "\ntomer#mail.com". How can I erase the "\n" char in artillery?
P.S.
The way to check your HTTP request is (I was unable to find documentation for this):
In cmd do the following command:
set DEBUG=http,http:capture,http:response
Afterwards, every regular artillery request will give you a http debug mode as following:
http request: {
"url": "https://host.com/api/user/login",
"method": "POST",
"headers": {
"user-agent": "Artillery (https://artillery.io)"
},
"json": {
"email": "\ntomer#mail.com",
"password":"9526e7bb980ba35a1788d46d4a2aaaaa3d941d2efc8a4fcb1402d1"
}
}
}
I solved the problem by using JS as follows (solution is based on this)
In the config section of the yml I set that the JS file to be called would be login.js by adding the following line:
processor: "./js/login.js"
When sending my login request I called the "setJSONBody" function as following:
- post:
url: "https://dev-api.host.com/api/user/login"
beforeRequest: "setJSONBody"
json:
email: "{{ user }}"
password: "{{ password }}"
Here is my login.js file:
//
// my-functions.js
//
module.exports = {
setJSONBody: setJSONBody
}
function setJSONBody(requestParams, context, ee, next) {
context.vars.user = context.vars.user.replace('\n',''); //erases from user name any \n char
return next(); // MUST be called for the scenario to continue
}

Can't access POST Variables sent from angular 4 in slim php

I'm trying to build a little Angular 4 Application with a rest api build with slim php. I'm having touble to access the POST variables on specific routes, while it works perfectly on at least one route. Here is my code:
// Log In A League { "email": $email, "pass": $pass }
$app->post('/api/users/league-login', function(Request $request, Response $response){
require "user_management/league_login.php";
$logIn = new LeagueLogIn();
$logIn->logIn($request->getParam("email"), $request->getParam("pass"));
});
Angular sends this JSON:
Object { email: “test#test.com", pass: "000" }
This works perfectly. But on this rout I can't access the POST variables with $request->getParam()
// Add Team To A League { "name": $name, "email": $email }
$app->post('/api/league/team', function(Request $request, Response $response){
require "user_management/team_create.php";
$user = authorizeToken($request->getHeader('Authorization'));
$teamCreate = new TeamCreate();
$teamCreate->create($request->getParam("name"), $request->getParam("email"), $user);
});
Angular sends this JSON
Object { name: "name", email: "test2#test.com" }
As soon as I add double quotes on the keys manually for the request:
Object { "name": "name", "email": "test2#test.com" }
it works perfectly.
Does somebody know what kind of problem this is, or what I'm overlooking?