HTML for emails
This commit is contained in:
@@ -33,15 +33,45 @@ export async function sendGmail(
|
|||||||
oauth.setCredentials({ refresh_token: refreshToken });
|
oauth.setCredentials({ refresh_token: refreshToken });
|
||||||
|
|
||||||
const gmail = google.gmail({ version: 'v1', auth: oauth });
|
const gmail = google.gmail({ version: 'v1', auth: oauth });
|
||||||
const raw = Buffer
|
|
||||||
.from(
|
const wrappedHtml = `<!DOCTYPE html>
|
||||||
[`To: ${to}`,
|
<html lang="en">
|
||||||
'Content-Type: text/plain; charset="UTF-8"',
|
<head>
|
||||||
'Content-Transfer-Encoding: 7bit',
|
<meta charset="UTF-8">
|
||||||
`Subject: ${subject}`,
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
'',
|
<title>${subject}</title>
|
||||||
text].join('\n'))
|
<link href="https://fonts.googleapis.com/css?family=Lato:400,700&display=swap" rel="stylesheet">
|
||||||
.toString('base64url');
|
<style>
|
||||||
|
body { font-family: 'Lato', Arial, sans-serif; margin: 0; padding: 0; background: #f9f9f9; }
|
||||||
|
.container {
|
||||||
|
max-width: 480px;
|
||||||
|
margin: 0 auto;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0,0,0,0.04);
|
||||||
|
padding: 24px 16px;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.container { padding: 16px 4px; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">${text}</div>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
|
||||||
|
const message = [
|
||||||
|
`To: ${to}`,
|
||||||
|
'Content-Type: text/html; charset="UTF-8"',
|
||||||
|
'Content-Transfer-Encoding: 7bit',
|
||||||
|
`Subject: ${subject}`,
|
||||||
|
'',
|
||||||
|
wrappedHtml
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
const raw = Buffer.from(message).toString('base64url');
|
||||||
|
|
||||||
await gmail.users.messages.send({
|
await gmail.users.messages.send({
|
||||||
userId: 'me',
|
userId: 'me',
|
||||||
|
|||||||
Reference in New Issue
Block a user