Firebase email trigger not working on gmail - google-cloud-firestore

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

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.

In Gmail, using Google Apps Script, is it possible to forward the TRANSLATED emails which I receive to another email address?

I receive many emails in Japanese everyday (I am living in Japan). Gmail automatically detect that the email is written in Japanese, so that one can click the "translate" button and get it translated. I would like to forward the translated email to another email address (or to a mailing list). It is easy to set up the mail forwarding, but when I do, only the original message (in Japanese) is forwarded. So my question is:
Is it possible, using Google Apps Scripts script (or any another tool), to forward the TRANSLATED emails which I receive to another email address?
I am a very beginner with Google tools, so any help is appreciated!
You can use the built-in LanguageApp service to translate text.
GmailApp.getInboxThreads().forEach((thread) => {
thread
.getMessages()
.filter((message) => {
return (
message.getFrom().toLowerCase().indexOf("sender#example.com") !== -1
);
})
.forEach((message) => {
if (MailApp.getRemainingDailyQuota() > 1) {
message.forward("email#example.com", {
htmlBody: LanguageApp.translate(message.getBody(), "jp", "en"),
});
}
});
});
To complete #Amit's answer:
You can build your filter based on the sender using the .getFrom() method on a message instance. Here you can find an example.
GmailApp.getInboxThreads().forEach( thread => {
thread.getMessages().forEach( message => {
if (message.getFrom() === "email2#example.com" {
message.forward("email#example.com", { htmlBody: LanguageApp.translate(message.getBody(), "jp", "en") }
}
});
});
Reference
GmailApp

how to update an subscription without id in mail chimp rest api

I really like the new Mail Chimp REST API - it is easy to create subscriptions by PUT and those can be updated using the subscription id.
But I would like to update a subscription simply using the email address, because I do not want to save any new Mail Chimp Id in my Middle-ware application, as long as the email should be sufficient as identifier?
To update a List Member the API is:
/lists/{list_id}/members/{id}
but I would prefer a simpler way:
/lists/{list_id}/members/{email}
is something like this possible?
The subscriber's ID is the MD5 hash of their email address. Since you would have to make a function call to URL Encode the email address for your second way, using the first way is just as easy.
See this help document on managing subscribers for more details.
More specifics on updating a subscriber via MailChimp's REST API.
// node/javascript specific, but pretty basic PUT request to MailChimp API endpoint
// dependencies (npm)
var request = require('request'),
url = require('url'),
crypto = require('crypto');
// variables
var datacenter = "yourMailChimpDatacenter", // something like 'us11' (after '-' in api key)
listId = "yourMailChimpListId",
email = "subscriberEmailAddress",
apiKey = "yourMailChimpApiKey";
// mailchimp options
var options = {
url: url.parse('https://'+datacenter+'.api.mailchimp.com/3.0/lists/'+listId+'/members/'+crypto.createHash('md5').update(email).digest('hex')),
headers: {
'Authorization': 'authId '+apiKey // any string works for auth id
},
json: true,
body: {
email_address: email,
status_if_new: 'pending', // pending if new subscriber -> sends 'confirm your subscription' email
status: 'subscribed',
merge_fields: {
FNAME: "subscriberFirstName",
LNAME: "subscriberLastName"
},
interests: {
MailChimpListGroupId: true // if you're using groups within your list
}
}
};
// perform update
request.put(options, function(err, response, body) {
if (err) {
// handle error
} else {
console.log('subscriber added to mailchimp list');
}
});

Meteor : Email a Template in Client using Mailgun

I have a Template in client
<template name="sendThis">
<img src="logo.png"><br>
<h3>Welcome to Meteor NewBie</h3>
Dear {{name}},
<p>You received this Email because you have subscribed to http://www.example.com</p>
</template>
I would like to send this Template(sendThis) as HTML body in my Email to subscribers.
I am using Mailgun as my Email Client. What are the steps I should take to make this happen as a subscriber clicks a button with an id "subscribe".
PS: I have multiple helpers in this template, multiple in the sense more than 20.
Thanks in advance.
Mahesh B.
One way to solve this is to use Blaze.toHTMLWithData to render your template (with a context) to an HTML string. You can then call a method on your server which emails the user with the appropriate subject and address. Here's an example:
client
var sendSignupEmail = function() {
// This assumes this first email address is the one you want.
// In some cases you may want the first verified email, but not
// during signup.
var address = Meteor.user().emails[0].address;
var subject = 'Thanks for signing up!';
// Here I used username - replace this with the appropriate data
// like Meteor.user().profile.firstName or something.
var body = Blaze.toHTMLWithData(Template.sendThis, {
name: Meteor.user().username
});
Meteor.call('sendEmail', address, subject, body);
};
server
Meteor.methods({
sendEmail: function(to, subject, html) {
check([to, subject, html], [String]);
this.unblock();
return Email.send({
to: to,
from: 'something#example.com',
subject: subject,
html: html
});
}
});
Also make sure your MAIL_URL environment variable has been defined.

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

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);
}