Send mail for multiple user and the each recipents have only his email address not the others - email

I am new bie for send grid. I have checked this url for two emails "https://sendgrid.com/api/mail.send.js..." and got the mail successfully in both emails.
The mail received by the users from the above URL have both email address in "TO" field like
For ex. User Test To: test#example.com;test2#example.com. and For User test2 To: test#example.com;test2#example.com.
As per my requirement i want to send mail for multiple user and the each recipents have only his email address not the others.
For ex. User Test To: test#example.com and For User test2 To: test2#example.com.
Can this scenario is possible with send grid.
Thanks

You can send the same email to multiple recipients by using the SendGrid SMTP API's to parameter.
To do this you'll set an X-SMTPAPI: header in your message, this header will include the JSON to communicate with SendGrid's SMTP API. The header will look as such:
X-SMTPAPI: { "to": [ "test#example.com", "test2#example.com" ] }
Each recipient will receive a unique email, addressed only to them.
Be aware: you'll still need to set a To: header for the message to send, however you can set this to yourself or one of the recipients (and then exclude them from the JSON list).

Send grid being a standard SMTP server will respond as if you are sending email from gmail, yahoo or outlook.
The scenario is not possible that I am aware of. I have only incorporated it into 2 applications, so I am certain there are better experts.
As an alternative you could test using the blind copy, The problem with that is would need a main address in the To field, which may not fill your requirement.

Send email on Azure Mobile Service /NodeJS
var sendgrid = new SendGrid('KEY');
sendgrid.send({
to: toEMail, // ["email1#mail.com", "email2#mail.com",...]
from: fromEMail,
subject: subject,
text: body
}, function (success, message) {
console.log("send mail: " + subject);
// If the email failed to send, log it as an error so we can investigate
if (!success) {
console.error(message);
}
});

possible on Sendgrid. You can use the normal bcc on sendgrid via personalization, but we dont like it because the To: is always required. So my solution is sendgrid transactional email. This will send 1 email to multiple users (using sendgrid / php / laravel ):
$email = new \SendGrid\Mail\Mail();
$email->setFrom("sender#mail.com", "Sender Name");
$email->setSubject("Your subject");
$email->addTo(
"email.1#mail.com",
"User One",
[],
0
);
$email->addTo(
"email.2#mail.com",
"User Two",
[],
1
);
$email->addTo(
"email.3#mail.com",
"User Three",
[],
2
);
$email->addContent("text/plain", "your body");
$email->addContent("text/html", "<strong>your body</body>");
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
$response = $sendgrid->send($email);
return response()->json($response, 200);
} catch (Exception $e) {
return response()->json($e->getMessage(), 400);
}

Related

Impossible to Send Multiple Emails from Gmail after May 30th Update

I have code which has remained essentially unchanged for months. The code extracted an email address and email password from an .env file and was used for a few difference cases. Whenever a single user signs up, they would receive an email; and whenever an owner signs many employees up, each of them would receive and email.
The email account we used to send these emails was a Gmail, and was created before the May 30th update and allowed less secure apps access. This allowed it to work sending an individual an email when they signed up, and provided there was a 1 second delay between each employee signed up, it was able to handle the en masse emailing as well.
The email account we use has since been changed, this new email was created after the May 30th update. I jumped through all of the extra hoops to enable less secured apps on this new account, so it sends individual sign up emails with no issue. However, as soon as I attempt to execute the en masse emails (even with the one second delay) I get the following error:
Error: Invalid login: 535-5.7.8 Username and Password not accepted.
Now, this really makes no sense because it is a copy and paste job of the email syntax that DOES work meaning this code below works...
try{
// Creates the Transporter
const transporter = nodemailer.createTransport({
service: "Gmail",
auth: {
user: `${process.env.SIGNUP_EMAIL}`,
pass: `${process.env.SIGNUP_PASS}`
}
})
// Creates the Mail Object
const mailOptions = {
from: `${process.env.SIGNUP_EMAIL}`,
to: `${actualEmail}`,
subject: `Thank you for joining the TOM Team!`,
text: `We have recieved your Account Signup and are please to welcome you to the TOM Experience!`
}
// Sends the mail
transporter.sendMail(mailOptions, (error, response) => {
if (error){
throw new Error('Something went wrong, please try again \n' + error)
}
})
} catch(error){
console.log(error)
}
But this code DOES NOT (breaks on the first attempt no matter how many others there are after)
try{
const transporter = nodemailer.createTransport({
service: "Gmail",
auth: {
user: `${process.env.SIGNUP_EMAIL}`,
pass: `${process.env.SIGNUP_PASS}`
}
})
// Creates the Mail Object
const mailOptions = {
from: `${process.env.SIGNUP_EMAIL}`,
to: `${actualEmail}`,
subject: `Thank you for joining the TOM Team!`,
text: `We have recieved your Account Signup and are please to welcome you to the TOM Experience! \nUpon recieving this email, you will have a new TOM Account for the mobile app. Please use this email, and the password "${passwordToUse}" to login and get started!`
}
// Sends the mail
transporter.sendMail(mailOptions, (error, response) => {
if (error){
console.log(error)
throw new Error('Something went wrong, please try again \n' + error)
}
})
}
catch(err){
console.log(err)
throw new Error(`Something went wrong emailing ${actualEmail}. Please check this is the proper address.`)
}
Is it just impossible to send gmails en masse now? Even with a 1 second delay? Even if not, why is the very first email failing? I truly have no idea why I'm facing these errors
I'm not sure why this is, but increasing the wait time from 1000 milliseconds to 1500, and then back to 1000 did the trick.
I'm not sure, maybe the new email just needed to get baby-stepped into sending multiple at a time.

Firebase email trigger not working on gmail

I use firebase email trigger and trying to send an email to my gmail account and another account which is not gmail. I received email only on my another account, gmail doesn't work.
Here is my code.
db.collection('mail').add({
to: 'user#gmail.com',
cc: 'user#example.com',
message: {
subject: 'Welcome',
html: 'Hello',
},
})
Here is my mail collection response
Response looks fine.
I received email only on user#example.com account.
I'd be very grateful if some could help me.
Thanks in advance.
The Trigger Email extension for Firebase makes no distinction in how it handles gmail destinations vs other email addresses, so it is very unlikely that this difference happens in the sending of the email.
More likely the email is getting caught in either the spam filter of gmail, or in another spam filter along the way to gmail. I recommend checking your gmail spam box first.
I have changed from email and it works now.
Thanks
Be sure to check in the firebase/firestore itself,
the errors will show in the document itself:
[![error code in firestore][1]][1]
as mentioned, do check your trigger-email settings, that they are linked to the correct collection:
[![collection linked to trigger-email][2]][2]
// Firestore data converter
export const contactFormConvertor = {
toFirestore: (contactform: ContactformDTO) => {
return {
to: <INSERT email you wish to receive the mail on>,
name: contactform._name,
from: <INSERT email you use to send the mail from>,
replyTo: contactform._email,
message: {text: contactform._message + '\n\nkind regards, ' + contactform._name,
subject: contactform._subject}
};
},
fromFirestore: (snapshot: { data: (arg0: any) => any; }, options: any) => {
const data = snapshot.data(options);
return new ContactformDTO(data.name, data.email, data.subject, data.message);
}
};```
[1]: https://i.stack.imgur.com/08cIQ.png
[2]: https://i.stack.imgur.com/m4Sod.png

Only show whose own email after sending email to multiple recipients

I sent the mail to multiple recipients but when I show the mail box's 'Recipient',
there is shown the multiple recipients.
I want the mail box's Recipient to show only whose own email after sending mail to multiple recipients.
I have tried change the Message.RecipientType.TO -> Message.RecipientType.BCC
but it was hide all of recipients.
How could resolve it?
msg.setFrom(new InternetAddress("test44#test.com", "test account"));
msg.setRecipients(Message.RecipientType.TO, toClient);
msg.setSubject(title);
msg.setContent(content, "text/html; charset=UTF-8");
Transport trans = session.getTransport("smtp");
trans.connect();
try {
trans.sendMessage(msg, toClient);
} catch (Exception e) {
e.printStackTrace();
} finally {
trans.close();
}

Play Framework [play-mailer]: how to ensure each receiver sees only his or her email address in the TO field

Here below is the code to send an email with play-mailer:
import play.api.libs.mailer._
...
val email = Email(
"My Subject",
"Me <j3d#domain.com>",
Seq("john#domain.com", "joe#domain.com", "jack#domain.com"),
bodyText = Some("Some text..."),
bodyHtml = Some("<p>Some text...</p>")
)
MailerPlugin.send(email)
The problem is that receivers see all the recipients the email was sent to. Of course, an option could be to invoke MailerPlugin.send for every single recipient... but I'm wondering if there is a better way to ensure each receiver sees only his or her email address in the to field.
Perhaps the best solution will be using hidden recepient which aka BCC. Emailer plugin has method addBcc(String address):
public void addBcc(String address) {
this.bcc.add(address);
}
Regards!

Google Form - One form submission sends two (unique) emails

Please excuse my possibly "lame" question here. I have searched everywhere and have not been able to find a solution.
Google forms -
I have one form that collects two email addresses.
I need to have each email entered into the form receive a "unique" response when the form is submitted.
Below is an example of the code I've been "trying" to make work. (Where I only get the latter email to send)
I thank you in advance for your time.
Oliver
// this would be the first email sent to e.values[3] - the first email on the form
function formSubmitReply(e) {
var userEmail = e.values[3];
MailApp.sendEmail(
userEmail,
"Help Desk Ticket1",
"Thanks for submitting your issue. \n\nWe'll start " +
"working on it as soon as possible. \n\nHelp Desk",
{name:"Help Desk"}
);
}
// this would be the second email sent to e.values[4] - the second email on the form
function formSubmitReply(e) {
var userEmail = e.values[4];
MailApp.sendEmail(
userEmail,
"Help Desk Ticket - FYI form is sent",
"The form a has been submitted. \n\nWe need to start " +
"working on it as soon as possible. \n\nThe Reger Group",
{name:"The Reger Group"}
);
}
This is a blind shot (haven't tested), but here is my guess: you are creating the same function twice, thus the second replaces the first one. Functions are unique, if you can only have one function as callback of the form submission, you should adapt it to do everything you need within the one function call.
Here's what you could do:
// Sends distinct messages for each recipient
function formSubmitReply(e) {
// First mail recipient and message
MailApp.sendEmail(
e.values[3],
"Help Desk Ticket1",
"Thanks for submitting your issue. \n\nWe'll start " +
"working on it as soon as possible. \n\nHelp Desk",
{name:"Help Desk"}
);
// Second mail recipient and message
MailApp.sendEmail(
e.values[4],
"Help Desk Ticket - FYI form is sent",
"The form a has been submitted. \n\nWe need to start " +
"working on it as soon as possible. \n\nThe Reger Group",
{name:"The Reger Group"}
);
}