Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

embed a button in email created by script

I have a script from a sheet which can create and send an email. The email contains a link to form. But the link is now very long and pretty ugly. Can I instead add a button to the email body and have the link held with the button? Would all have to created by the script though.

Thanks

Max

question from:https://stackoverflow.com/questions/66046977/embed-a-button-in-email-created-by-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You cannot make buttons but you make links with custom text using an HTML body. Notice that email HTML is more restrictive than regular HTML that you find in pages (which is a good thing for security reasons). Usually when you make an HTML body you also make a plain text version of it, so it’s easier to read on every device.

Here is an example using Google Apps Script MailApp:

MailApp.sendEmail(
  'to@something.com',
  `Requested link`,
  `Here is the requested link:
https://example.com/?ugly=true`,
  {
    htmlBody: `<a href="https://example.com/?ugly=true">Click here to go to the page</a>`
  }
)

Notice that if you are mailing automatically you probably want to use bcc instead of recipient to prevent leaking emails to multiple people and set noReply (if have a custom domain) if you don't want them to reply:

MailApp.sendEmail(
  '',
  `Requested link`,
  `Here is the requested link:
https://example.com/?ugly=true`,
  {
    bcc: 'to@something.com',
    htmlBody: `<a href="https://example.com/?ugly=true">Click here to go to the page</a>`,
    noReply: true
  }
)

References


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...