I've written a very simple email script in a google sheet.
I have tested the script by using my own email address, but when I use a Facebook GRoup email address, the email bounces back from Facebook with a "POL-P6 http://postmaster.facebook.com/response_codes?ip=209.85.220.199#pol-m Message refused" message.
If I send the exact same email to the facebook group using gmail, rather than sheets, the email does not bounce, and is successfully posted.
I'm thinking that this is related to SPF and DKIM, but I'm not sure. I would appreciate any light on this.
Possible solutions I'm open to:
1) How to correctly set the SPF/DKIM to allow sheets to send the email.
2) A free email scheduler that will read the subject and body from a preconfigured file, and send the email on a future date
3) Other config that I've obviously overlooked.
I'm including the code that I'm using here:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 10; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 6)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var subject = row[1]; // Second column
var message = row[2]; // Third column
if(emailAddress != "")
{
MailApp.sendEmail(emailAddress, subject, message);
}
}
}
This is a sample from the sheet than I'm using:
Email Subject Message Date Time Repeat
xxxx#groups.facebook.com Check out all the other languages https://www.facebook.com/xxxxxxxxxx/events 24/05/2016 16:00:00 Weekly
This is the error message I received from the Facebook server:
Delivery to the following recipient failed permanently:
xxxx#groups.facebook.com
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the server for the recipient domain groups.facebook.com by msgin.vvv.facebook.com. [66.220.159.18].
The error that the other server returned was:
554 5.7.1 POL-P6 http://postmaster.facebook.com/response_codes?ip=209.85.220.200#pol-m Message refused
----- Original message -----
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:message-id:date:subject:from:to;
bh=Tha9xrs+SsMgr1f6g/kqP/M1YN17QMZsR4wIogukb7M=;
b=LW0tiMl7DvjD0DnUf/rU0YANFsVkSGZ2pPiBZwQMv00hK3JvRwjLXseDzhVddgBKY0
1tfxnBuff7oGruFgdwf3rDddchU77CoVKCH6sQvBNU6d442lWdrqSpw8UBTuJUPrucz/
kN+PKHe+5hPnl4tiPWnL3P9Nnw1Q/jPOkq5LCbVDHBK55nXaceBZRyp1B8474SrLN6AX
MicGGoSK74BJsvKYdTubzjCLvpiC2LVj4kmRPz3YBuMQhPZrkNGUQ09WNXxeyDJ2mAdL
TZv/K7ZA5eRNvhbdDWoA4QFdzfWEHejnBBj+yfGVSNUue2OrAD7hKlEDrupmm0sQHPLi
RQKw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20130820;
h=x-gm-message-state:mime-version:message-id:date:subject:from:to;
bh=Tha9xrs+SsMgr1f6g/kqP/M1YN17QMZsR4wIogukb7M=;
b=kC7S8oDRlE8ACX2wizIPkQbQlNjZaUXIn2jePw+/cmqoVYNAH7vwslcQPhrjjRkLlP
FcztAQTp7blzosxqmxz1M9jijPnokphR6rH1t17l9V7hcNjX92xc2PRRkuSDauIt6OjK
FtTJgwDjQhz0ilHMqntJIVzjA+J964eEH6m1eLceTKAcz+5+ukcUSg/LHVXOe3IS34SE
M5CHm5jkYWQxL6vLJYNfPbE+6tMLwvLmkYkGmPtVD0Sxghn1IYtinHpaC/e5n8MA7REe
V1gI+Fl6ki3CgVLLOCKcYs4dhYIVG4Bk6TkspMkrbWJwLuPsWCHBVoDNXa26eS2nfkzu
RkDA==
X-Gm-Message-State: ALyK8tKUQtlhdFcKfFUpHkCdvkXIiAo1Qny6c/VPOHziRvjSsAUUrZP+GpsNS0iKSW0zfa7dbxPsOHZpoicerg==
MIME-Version: 1.0
X-Received: by 10.129.71.213 with SMTP id u204mr3993391ywa.51.1464114280537;
Tue, 24 May 2016 11:24:40 -0700 (PDT)
Message-ID: <001a114c6ec09a28e405339aab2a#google.com>
Date: Tue, 24 May 2016 18:24:40 +0000
Subject: Check out all the other languages
From: mmmmm#gmail.com
To: xxxx#groups.facebook.com
Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes
https://www.facebook.com/xxxxxxxxx/events
Any help is appreciated.
Thank you.
So, after reporting the problem to Facebook, the emails began arriving to the group page. So, it wasn't the content, but something blocked on FB's side. Problem solved. Good luck to anyone who has the same problem.
Related
I have tried to use the search function, but did not find a solution for my problem, or I do not understand enough yet.
I have written a script for google forms, that sends an automatic email to two email addresses, when an user submits the form. I have build in some information that should show in the email subject and puts the input from the forms into the email, with some simple HTML formatting.
My problem is, that the emails always have my Email address as the sender (the account I used for creating the form)
I would like to have the senders email, the one that is submitting the form.
How is that possible?
Here is the code:
function sendFormByEmail(e)
{
// Sent to Email address
var email1 = "123#abc.com";
var email2 = "345#abc.com";
// Variables
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var txt = "";
var subject = "Example text: ";
// Var e = form input as array.
// Loop through the array.
for(var i in headers){
txt += "<b>" + headers[i] + '</b>' + ': '+
e.namedValues[headers[i]].toString() + '<br><br>';
}
// Insert variables from the spreadsheet into the subject.
// Create email subject
subject += "Example text " + e.namedValues[headers[2]].toString();
// Send the email
MailApp.sendEmail(email1, subject, "", {htmlBody:txt});
MailApp.sendEmail(email2, subject, "", {htmlBody:txt});
}
It is not possible to send the mail as the user who submitted the form as the script is running from the user account and the mailapp will send the mail from that account only. you can change the display name according to the user name who submiited the form by the parameter name. Also you can change the email to noreply#domainName.com by adding the parameter noReply in mailApp syntax. However you cannot change it to the user who submitted the form
You can refer this documentation for the above parameters : https://developers.google.com/apps-script/reference/mail/mail-app
Hope this could help
First of all I'm completly new at programming so I think my question is really simple but i couldn't find an answer that really matches my issue.
I created a form in googleforms and I want to send this form to my e-mail every tuesday and every thursday by googlescript. (the embed form, not the link)
Firstly, I'm not beeing successful not even sending it to my e-mail.
I tried two methods that I found here but thats what I got:
this is the code im using:
function sendForm(form,email) {
var form = FormApp.getActiveForm();
var email = "myemail#gmail.com"
var formUrl = form.getPublishedUrl();
var url = form.getPublishedUrl();
var response = UrlFetchApp.fetch(url);
var htmlBody = HtmlService
.createHtmlOutput(response)
.getContent()
;
MailApp.sendEmail({
to: email,
subject: "subject",
htmlBody: htmlBody,
});
}
The other code i tried just give me the e-mail message "HtmlOutput" and not the form.
Can someone help me?
Thanks in advance.
I am trying to reply outlook email as we do manually it goes with previous conversations. But Below code is giving some error : Failed to send to the recipient address..I need to know how i can send it back to the person who sent me email..
import win32com.client, datetime
from datetime import timedelta
outlook =win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") # to trigger outlook application
inbox = outlook.GetDefaultFolder(6) # 6 is used for the index of the folder
messages = inbox.Items
message = messages.GetLast()# message is treated as each mail in for loop
for message in messages:
if message.Subject=="request": # based on the subject replying to email
#body_content = message.body
message.Reply()
message.Body = "shortly will be processed!!!"
message.Send()
The reply is a MailItem returned by reply(). So try this:
reply = message.Reply()
reply.Body = "shortly will be processed!!!"
reply.Send()
continuing to above answer
to reply all:
`rplyall=message.ReplyAll()`
to reflect previous conversations:
`rplyall.Body="your message here"+rplyall.Body()`
`rplyall.Send()`
Since MailItem.Body is a String and it is not callable. Reference document
I think the correct code in #Akhil 's answer is
rplyall.Body = "your message here" + rplyall.Body
rplyall.Send()
I'm using google apps script to get the responses of a specific form in an specific e-mail,
What I'm trying to do is use a google form to open support tickets, so people need fill some fields like, title, description and e-mail,
And when they submit the form, it will automatically open a ticket, but the e-mail will be always from the owner of the form, and this was a problem because we want that the person who opened the ticket receives email updates, so what I'm trying to do is this:
I put a field in the form asking the persons email, and I'm trying to put that e-mail into the reply-to...
And apparently I'm in the right way to catch that e-mail but the reply-to don't show the email that the persons filled the box, it appears an error: [Ljava.lang.Object;#34dfe075
Does any one can help me?
Here is my script:
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("SendGoogleForm")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function SendGoogleForm(e)
{
try
{
var email = "support#email.com";
var form = e.namedValues;
var subject = form["Title"];
var s = SpreadsheetApp.getActiveSheet();
var columns = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
for ( var keys in columns ) {
var key = columns[keys];
if ( e.namedValues[key] && (e.namedValues[key] != "") ) {
message += key + ' :: '+ e.namedValues[key] + "\n\n";
}
}
GmailApp.sendEmail(email, subject, message, {replyTo: form["E-mail"], from: "support#email.com"});
} catch (e) {
Logger.log(e.toString());
}
}
And here is the output of this:
from: support#email.com
reply-to: [Ljava.lang.Object;#34dfe075
to: support#email.com
date: Fri, Oct 17, 2014 at 10:55 AM
subject: New Test
The reply to, is broken :(
The values returned in the e.namedValues property are arrays, so you must access them as such.
Modify your sendEmail line as follows:
GmailApp.sendEmail(email, subject, message, {replyTo: form["E-mail"][0], from: "support#email.com"});
Note the [0] array index on the form["E-Mail"] field, indicating you want the first value in that array, which will be the email address entered.
See the example next to "e.namedValues" here: https://developers.google.com/apps-script/guides/triggers/events#google_sheets_events
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);
}