GmailApp.sendEmail() From Plus Address

被刻印的时光 ゝ 提交于 2019-12-08 08:59:25

问题


Question: Is there a way to override the account email address and replace it with a plus address on the same account?

I'm using the GmailApp.sendEmail() method in Google Apps.

The account e-mail address is a non-plus (obviously) address, but I use several plus addresses to filter messages into categories.

When I send a message with sendEmail(), it uses the main account address and it does not appear that there is a way to change this for a script.

While I can set the "name" for the account, I'd like to set the from address to a plus version of the account address.

(I remember running into this same issue with the Calendar user interface.)

So, I also tried setting a replyTo address using the advanced parameters. (This is not the way I'd prefer to do it.)

The replyTo parameter obviously accepts the address and the message that is sent contains the reply-to header. I've include the header lines below with 'example' replacing the account address.

Delivered-To: example+test@gmail.com

Reply-To: Richard Michael <example+pch@gmail.com>

From: Richard Michael <example@gmail.com>
To: example+test@gmail.com

When I use the Reply button in Gmail, however, the 'To' address that loads in the form is example+test@gmail.com which is neither of the possibilities I would expect. (It should be the Reply-to or, at worst, the From address.) The From address in the reply form is example@gmail.com, which is expected (but also the reason I want to 'send' from a plus address).

I've repeated this several times with the same result.

Of course, Gmail also allows you to 'send' from foreign accounts as well in the user interface after you've performed a validation check. So, you can't send from those addresses either.


回答1:


You have to use the parameter from: in the methode GmailApp.sendEmail.

Example

GmailApp.sendEmail('example@exapmle.com', 'Testmail', 'Hello Richard',
                        {name: 'Richard Michel', from: 'example+pch@gmail.com',}); 

I'm using Mail Merge HD and i edited the code a little.

In function fnMailmerge() i added the lines

  top_panel.add(myapp.createLabel("Please select your alias"));
  var lf = myapp.createListBox(false).setWidth(250).setName('from').addItem("Select aliases...").setVisibleItemCount(1);

  for (var i = 0; i < aliases.length; i++) {
   lf.addItem(aliases[i]);
  }

  top_panel.add(lf);

, added the last statement to this line (in the same function)

var handler = myapp.createServerClickHandler('startMailMerge').addCallbackElement(lb).addCallbackElement(name_box).addCallbackElement(bcc_box).addCallbackElement(lf);

and finaly editet the function Gmail.sendEmail

 GmailApp.sendEmail(rowData.emailAddress, emailSubject, emailText,
                        {name: e.parameter.name, attachments: attachments, htmlBody: emailText, cc: cc, bcc: bcc, inlineImages: inlineImages, from: e.parameter.from,});

This adds a dropdown list to the Mail Menu, where you can chose from your registered Aliases.



来源:https://stackoverflow.com/questions/12443014/gmailapp-sendemail-from-plus-address

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!