Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
874 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 Answer

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(
  '[email protected]',
  `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: '[email protected]',
    htmlBody: `<a href="https://example.com/?ugly=true">Click here to go to the page</a>`,
    noReply: true
  }
)

References


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...