gpt4 book ai didi

javascript - 带 Handlebars 的 nodemailer 无法正确显示样式

转载 作者:行者123 更新时间:2023-12-04 07:27:52 26 4
gpt4 key购买 nike

我正在发送一封带有 nodemailer 和 handlebars 的电子邮件,我正确地收到了电子邮件,但未应用样式。

这是我发送电子邮件的代码:

    const hbsConfig = {
viewEngine: {
extName: '.hbs',
partialsDir: path.join(__dirname, '../../../../src/modules/hq-nd/templates/'),
layoutsDir: path.join(__dirname, '../../../../src/modules/hq-nd/templates/'),
defaultLayout: ''
},
viewPath: path.join(__dirname, '../../../../src/modules/hq-nd/templates/'),
extName: '.hbs'
};

const transporter = nodemailer.createTransport({
host: 'smtp.sendgrid.net',
port: 465,
secure: true,
auth: {
user: 'zzz',
pass: process.env.SENDGRID_SECRET,
},
});
transporter.use('compile', hbs(hbsConfig));
const email = {
from: "Boxtribe <123@gmail.com>",
to: params.username,
subject: 'Reset your zzz Password',
template: 'forgot-password',
context: {
...user,
token: tokenRes.token,
url: process.env.HARMONY_URL
}
};
const response = await transporter.sendMail(email as Mail.Options);

这是我的模板:

<html>
<head>
<meta
content="text/html; charset=utf-8"
http-equiv="Content-Type"
/>
<link
href="https://fonts.googleapis.com/css?family=Lato"
rel="stylesheet"
type="text/css"
/>
</head>
<body>
<style>
body {
font-family: Lato, Tahoma, Verdana, Segoe, sans-serif;
}
.header {
margin: 0 auto;
min-width: 320px;
max-width: 620px;
}

.logo {
display: block;
margin: auto;
}

.center {
text-align: center;
}

.title {
margin: 0;
}

.invoice {
font-size: 14;
color: #71777D;
line-height: 1.2;
word-break: break-word;
}

.btn-success
{
color:#fff;
background: #22caab;
border-radius: 5px;
transition:.15s linear;
border-color: #22caab;

}

.powered {
font-size: 12;
line-height: 1.2;
word-break: break-word;
padding-top: 30px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
}
</style>
<div class="header">
<img
class="logo"
src="{{url}}img/teal_bto_head.png"
width="150"
alt="logo"
>
<h3 class="center title">
Reset Password
</h3>
<p class="invoice center">
Harmony recently received a request for a forgotten password.
</p>

<p class="invoice center">
To change your password, please press the next button:
</p>
<p class="invoice center">
<a href="{{url}}reset-password.php?t={{token}}" class="btn btn-success" >Continue Setup</a>
</p>

<p class="powered center">
Powered by Qorus Inc.
</p>
</div>
</body>
</html>

我在 http://tryhandlebarsjs.com/ 测试过并且正确显示:

enter image description here

但在电子邮件中没有应用 css 类:

enter image description here

最佳答案

找到问题了,这是因为我使用的是类而不是内联样式。当我将样式更改为内联时它已修复

关于javascript - 带 Handlebars 的 nodemailer 无法正确显示样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68125734/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com