Change Recipient Address Google Apps Script - google-app-engine

Is it possible to change the recipient address when using the reply function in Google Apps Script?
I want to receive an email from a random email account, mark it with a label and when scheduled, run the following code to reply to a desired email address rather than the original sender. The reason I want to reply is to keep it in the same thread. I have tried nearly all variations of the following code and can't get it to work the way I want it to:
thread.reply("This is a message.", {
htmlBody: "This is a message.",
name: "My Name",
recipient: "DESIRED#EMAIL.com",
replyTo: "DESIRED#EMAIL.com",
to: "DESIRED#EMAIL.com"
});

If you're asking to generate a random email address and send a real email from that address... that's not possible.
However... you could set the replyTo optional parameter as a random address - though when users would try to reply to that thread they would get a bounce-back notification that the address could not be reached. However, the original sender (the non-random address) would still be visible in the original message.
If you look at the GmailApp docs (replying)/(sending), you'll notice a few limitations. The sender's address (from) must be a valid Alias, if you're sending mail from MailApp (Google Apps Script).
However, there are plenty of methods in the GmailMessage class such as getFrom() and getReplyTo() that would allow you to get/set the message's from/replyTo parameters and have them be the same value. That way, when you reply to a message you will always be in the same thread.

Related

Sending to another user with e-mail address

I am trying to create a script in Python to transfer funds to another Coinbase user when all I have is an e-mail address. I have been unsuccessful so far. How do I get another user's "id" when all I have is their e-mail address?
As a follow on, can I add a memo/note to the transfer? If so, how?
Finally figured it out with a little bit more searching and trial and error. For anyone else who may have this question:
First get the account ID for the currency you want to send.
account_list = client.get_accounts()['data']
ETH_id = [acc['id'] for acc in account_list if acc['balance']['currency'] == "ETH"][0]
Then use the send_money function (not transfer_money) to send to an e-mail address.
client.send_money(ETH_id,to="<e-mail address>", amount="0.0005", currency="ETH", description = "Hey look, it worked.")
The description keyword is for the memo.

Google Apps Script - Gmail Edit and, after, forward a message

Wherever I receive a message that contains "Nova reserva" in subject, I need to send an email to "accumakerapp-103#forms.zohocreator.com" with this EXACT format:
Remetente : (mail address of the sender)
Destinatário : (mail address of the receiver)
Assunto : (mail subject)
Texto : (mail body)
Someone can help me??
You can refer to the documentation. To be able to filter the required subject, use getSubject(). Then, when you already got the email that you needed using the method above proceed to create a reply message with your specified format using reply(body), reply(body, options), replyAll(body, options) whichever is applicable/suit your requirements. Additionally, if you want to forward the exact message, use forward(recipient, options).

Sending multiple emails in a row in GAE

I have a GAE based app (python) and I'm trying to implement automatic email sending. When only one email is sent it works fine (both local and deployed). However, when I try to send two emails in a row the script only works on my local dev server. If the application is deployed to Google a strange mixup occurs. It seems like the body of the first email is sent to the recipient of the second one and then the application throws an internal server error.
Here's my code:
class MailSender(webapp.RequestHandler):
def get(self):
firstname=self.request.get('firstname')
lastname=self.request.get('lastname')
email=self.request.get('email')
city=self.request.get('city')
state=self.request.get('state')
country=self.request.get('country')
sender_address = firstname+" "+lastname+" <"+users.get_current_user().email()+">"
subject = "Subject 1"
body = "Name: "+firstname+"\nLast name: "+lastname+"\nEmail: "+email+"\nCity: "+city+"\nState: "+state+"\nCountry: "+country
mail.send_mail(sender_address, "address1#ourdomain.com", subject, body)
sender_address1="address1#ourdomain.com"
subject1="Subject 2"
body2="message"
mail.send_mail(sender_address1, email, subject1, body1)
self.response.out.write('{"status":"true"}')
It seems you didn't set a valid sender address in second mail.
https://cloud.google.com/appengine/docs/python/mail/sendingmail
The sender address must be one of the following types:
The address of a registered administrator for the application. You can add administrators to an application using the Administration Console.
The address of the user for the current request signed in with a Google Account. You can determine the current user's email address with the Users API. The user's account must be a Gmail account, or be on a domain managed by Google Apps.
Any valid email receiving address for the app (such as xxx#APP-ID.appspotmail.com).
Any valid email receiving address of a domain account, such as support#example.com. Domain accounts are accounts outside of the Google domain with email addresses that do not end in #gmail.com or #APP-ID.appspotmail.com.
You might need to use the EmailMessage object the way you see here. Did you try using a loop to send emails? The following works for me.
for detail in details:
subject = detail.title or 'Reminder'
message = mail.EmailMessage(sender='Business <info#business.com>', subject=subject)
message.body = """
Hello!
"""
message.to = detail.email
message.send()

How to remove default disclaimer in javamail

When sending emails via javamail, the following is always appended to the bottom of each message:
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager. This message contains confidential information and
is intended only for the individual named. If you are not the named
addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received
this e-mail by mistake and delete this e-mail from your system. If you
are not the intended recipient you are notified that disclosing,
copying, distributing or taking any action in reliance on the contents
of this information is strictly prohibited.
How does one prevent this?
(NOTE: This problem is extremely frustrating to research on the web due to the fact that a disclaimer of this form is attached to so many indexed documents! :-(
JavaMail is not doing that, it is your outgoing SMTP server appending it to each message, probably set up by IT.
To confirm, you can use gmail's servers (with a personal account) and you will see it does not get added to the messages.
This should work. Pay attention to the form in which email body get parsed. In my case the emailBody string is on one line, so you have to put the "#Your disclaimer Here#" on one line. Answer for who will come in future.
public String deleteDisclaimer(String emailBody) {
String disclaimer = "#Your disclaimer here#";
if (emailBody.contains(disclaimer)) {
System.out.println("Deleting Disclaimer..");
return emailBody.substring(0,emailBody.indexOf(disclaimer));
}
System.out.println("DISCLAIMER NOT FOUND!");
return emailBody;
}

Target email address validiation

Before the client sends a new email, he/she specifies one or more (To) destination addresses. Is there any way to check the validity of these emails before sending the message ?
Define "validity".
This JavaMail FAQ entry might help.
The InternetAddress class only checks the syntax of the address. The InternetAddress class is not able to determine whether the address actually exists as a legal address. It is not even possible to verify the host name if the application is running behind a firewall or isn't currently connected to the Internet.

Resources