I tried to send multiple attachment using nodemailer. But It sends only the first attachment. Why is the second attachment not being sent? This is my mailOption code segment.
let mailOptions = {
from: 'test#gmail.com',
to: 'test#gmail.com',
subject: 'Test',
text: 'Email from nodemailer',
attachments: [
{ filename: 'cv.pdf', path: './uploads/cv_uploads/cv.pdf' },
{ filename: 'cover.docx', path: './uploads/cover_uploads/cover.docx' },
],
}
Related
I am trying to use the sendmail functionality of the Azure DevOps WorkItemTracking api; but get the error "Value cannot be null. Parameter name ClientRecipients"
It's not a field in the API - so frankly I'm lost.. https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/send-mail/send-mail?view=azure-devops-rest-7.1
Response
{"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: clientRecipients","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}
Source code
const sessionToken = await VSS.getAccessToken();
const authToken = authTokenManager.getAuthorizationHeader(sessionToken);
$.ajax({
type: 'POST',
url: `https://dev.azure.com/${organization}/${project}/_apis/wit/sendmail?api-version=7.1-preview.1`,
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
message: {
body: 'Hello World',
subject: 'My email',
to: {
tfIds: ['my-profile-id']
}
},
projectId: project
}),
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', authToken);
},
success: (e) => {
console.log(e);
},
error: (e) => {
console.error(e);
}
});
(updated to include token code)
I found through experimentation that the API requires the "cc" field to be present:
"message": {
"body" : "Test Body",
"cc" : {},
"to" : {
"tfsIds" : ["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"],
},
"replyTo" : {},
"subject" : "Test Subject"
}
I am an engineer who makes web systems in Tokyo.
I'm making a search system using Grid.js, but I faced a problem.
I don't know the solution because it's not in the documentation.
Since this system uses Vue 2.x, it uses axios.post with Custom HTTP Requset.
I was able to get the list, but I'm having trouble implementing sorting, pagination, and keyword search.
I want to send parameters by Post request.
Please tell me how to implement this.
The code is below
data() {
return {
columns: [
{name: 'user name', id: 'user_name'},
{name: 'email', id: 'email'},
],
page: {
enabled: true,
limit: 100,
server: {
body: (prev, page) => {
console.log(page) // OK, show page number 0,1,2...
return {
page: page
}
}
},
},
sort: {
},
search: {
server: {
// url: (prev, keyword) => `${prev}?q=${keyword}`
// what's this.
}
},
server: {
url: '/api/v2/users/list',
method: 'POST',
async data (opt) {
let response = await axios.post(opt.url)
return {
data: response.data.results.map(item => {
return {
username: item.username,
email: item.email,
}
}),
total: response.data.count,
}
}
},
};
OK.
Set POST payload this.
data() {
return {
columns: [
{name: 'user name', id: 'user_name'},
{name: 'email', id: 'email'},
],
page: {
enabled: true,
limit: 100,
server: {
body: (prev, page) => {
console.log(page) // OK, show page number 0,1,2...
return {
page: page
}
}
},
},
sort: {
},
search: {
server: {
// url: (prev, keyword) => `${prev}?q=${keyword}`
// what's this.
}
},
server: {
url: '/api/v2/users/list',
method: 'POST',
body: {},
async data (opt) {
let response = await axios.post(opt.url)
return {
data: response.data.results.map(item => {
return {
username: item.username,
email: item.email,
}
}),
total: response.data.count,
}
}
},
};
I'm using aws-sdk in my service to send emails. I'm getting below exception to a code which was working fine before.
const aws = require('aws-sdk');
var params = {
Destination: {
ToAddresses: [
'checkMail#gmail.com'
]
},
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: "HTML_FORMAT_BODY"
},
Text: {
Charset: "UTF-8",
Data: "this is sample"
}
},
Subject: {
Charset: 'UTF-8',
Data: 'Test email'
}
},
Source: 'AWS Services<awsEmails#awsService.com>'
ReplyToAddresses: [
'AwsServices<noreply#awsServices.com>'
],
};
// Create the promise and SES service object
var emailPromise = new aws.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise();
// Handle promise's fulfilled/rejected states
emailPromise.then(
function(data) {
//my logic on success goes here
}).catch(
function(err) {
//my logic on error goes here
});
I have tried using different API calls for email from AWS but all returns the same error.
Avoid require ALL aws-sdk if it's just to use a single service. For using SES, you can yarn add #aws-sdk/client-ses and then use it const { SESClient, SendEmailCommand } = require("#aws-sdk/client-ses");
I show you here a full exemple of sending email with SES in a nodeJS lambda function:
const {
SESClient,
SendEmailCommand,
} = require("#aws-sdk/client-ses");
const REGION = "eu-west-3"; // Use you AWS region
const ses = new SESClient({ region: REGION });
exports.handler = async function (event) {
const path = event.path;
if (path === "/send-email") {
const peopleAmount = 12;
const params = {
Source: "John Wick <john.wick#killer.com>",
Destination: {
ToAddresses: ["adresse1#test.com"],
},
Message: {
Body: {
Html: {
Data: `<span>This email is about <b>${peopleAmount}</b> people.</span>`,
},
},
Subject: {
Data: "Email Title",
},
},
};
try {
const data = await ses.send(new SendEmailCommand(params));
return {
statusCode: 200,
body: peopleAmount,
};
} catch (e) {
console.error(e, e.stack);
return {
statusCode: 400,
body: "Sending failed",
};
}
}
}
I hope it helps, here is documentation to use SES email template.
I am trying to use nodemailer to send emails via a mail server that I own in JustHost. I am using the SMTP settings provided by the hosting.
let transporter = nodemailer.createTransport({
host: 'mail.wegocuba.com',
port: 465,
secure: true,
auth: {
user: PROVIDERS.wegocuba.user,
pass: PROVIDERS.wegocuba.pass
},
tls: {
rejectUnauthorized: false
}
});
let configureMailer = (text, to) => {
return {
from: '"USER" <user#wegocuba.com>',
to: to, // list of receivers
subject: 'Hello world',
text: text,
};
};
mySendMail = (to, text) => {
let sender = configureMailer(text, to);
transporter.sendMail(sender, (error, info) => {
if (error) {
return console.log(error);
}
console.log(info.messageId);
});
},
When I call the mySendMail(to, text) function, the server respond without problems.
{ accepted: [ 'myemail#gmail.com' ],
rejected: [],
envelopeTime: 107,
messageTime: 73,
messageSize: 288,
response: '250 OK id=1eUGz4-003LtQ-RK',
envelope: { from: 'user#wegocuba.com', to: [ 'myemail#gmail.com' ] },
messageId: '<9efa8726-6d8b-2161-36d5-023b49799871#wegocuba.com>' }
But the email never reach the recipient, neither appears as sent in the SENT folder.
How can I know what really is happening in the mail server?
In Meteor application that incorporates Sendgrid transaction email templates for user invitations and notifications, I can't manage to replace substitution tags. Templated email is received, but without any difference.
Email.send({
from: "hello#domain.com",
to:email,
subject: "Subject",
sub: {
"{name}":post.createdBy,
"{title}":post.title,
},
headers: {
"X-SMTPAPI": {
"filters": {
"templates": {
"settings": {
"enable": 1,
"template_id": "xxxx"
}
}
}
},
"Content-Type" : "text/html"
}
});
I'm not using API directly, but rather Meteor Email package, but don't see that possible issue:
Meteor.startup(function () {
process.env.MAIL_URL = 'smtp://username:password#smtp.sendgrid.net:587';
});
This is my shortened email template:
Hey {name},
your post {title} has a new comment.
You need to put the subs in the X-SMTPAPI header as well. The X-SMTPAPI header itself should also contain valid JSON in a string.
Try this:
var xsmtpapi = {
"filters": {
"templates": {
"settings": {
"enable": 1,
"template_id": "xxxx"
}
}
},
"sub": {
"{name}": post.createdBy,
"{title}": post.title
}
}
Email.send({
from: "hello#domain.com",
to:email,
subject: "Subject",
sub: {
"{name}":post.createdBy,
"{title}":post.title,
},
headers: {
"X-SMTPAPI": JSON.stringify(xsmtpapi),
"Content-Type" : "text/html"
}
});
What I ended up doing was using smtpapi-nodejs NPM package.
The simple example would be:
var nodemailer = require('nodemailer');
var smtpapi = require('smtpapi');
var header = new smtpapi();
header.setFilters({
"templates": {
"settings": {
"enable": 1,
"template_id": xxx-template-id-xxx
}
}
});
header.addSubstitution('-name-', post.createdBy);
header.addSubstitution(-title-', post.title);
var headers = { 'x-smtpapi': header.jsonString() };
// Use nodemailer to send the email
var settings = {
host: "smtp.sendgrid.net",
port: parseInt(587, 10),
requiresAuth: true,
auth: {
user: "sendgrid_username",
pass: "sendgrid_password"
}
};
var smtpTransport = nodemailer.createTransport(settings);
var mailOptions = {
from: "Fred Foo <foo#blurdybloop.com>",
to: "bar#blurdybloop.com",
subject: "Hello",
text: "Hello world",
html: "<b>Hello world</b>",
headers: headers
}
smtpTransport.sendMail(mailOptions, function(error, response) {
smtpTransport.close();
if (error) {
console.log(error);
} else {
console.log("Message sent: " + response.message);
}
});