如何使电子邮件请求与动态 HTML 响应一起使用?
How can I make email requests work with dynamic HTML responses?
我正在使用 AWS SES (Nodejs) 发送 HTML 电子邮件。它适用于静态 HTML,但我不知道如何使其适用于动态 HTML。
nodejs 文件
HTML = "..." // load external html file
var params = {
Destination: {/* required */
ToAddresses:[abc@gmail.com, test@gmail.com]
},
Message: {/* required */
Body: { /* required */
Html: {
Data: HTML,
Charset: 'UTF-8'
},
},
Subject: { /* required */
Data: 'Test email', /* required */
Charset: 'UTF-8'
}
},
Source: "myemail@gmail.com"
}
ses.sendEmail(params, function(err, data) {
// If something goes wrong, print an error message.
if(err) {
console.log(err.message);
} else {
console.log("Email sent! Message ID: ", data.MessageId);
}
});
html 文件
<html>
<head></head>
<body>
<h1>Amazon SES Test</h1>
<p>Your order is placed.
<a href='https://example.com/id=1234125'>View your order</a>
</p>
</body>
</html>
我的问题:如何将 href 作为变量从 nodejs 文件传递到 html 文件。
欢迎任何建议。
您可以在 HTML 中使用占位符,例如:<a href="HREF_PLACEHOLDER">...</a>
.
然后在 HTML 上使用 string.replace() 将其替换为您想要的实际 href。
例如:
function dynamicHtml(href) {
return HTML.replace("HREF_PLACEHOLDER", href);
}
而不是将 HTML 传递给您的参数对象,而是将其传递 dynamicHtml()
我正在使用 AWS SES (Nodejs) 发送 HTML 电子邮件。它适用于静态 HTML,但我不知道如何使其适用于动态 HTML。
nodejs 文件
HTML = "..." // load external html file
var params = {
Destination: {/* required */
ToAddresses:[abc@gmail.com, test@gmail.com]
},
Message: {/* required */
Body: { /* required */
Html: {
Data: HTML,
Charset: 'UTF-8'
},
},
Subject: { /* required */
Data: 'Test email', /* required */
Charset: 'UTF-8'
}
},
Source: "myemail@gmail.com"
}
ses.sendEmail(params, function(err, data) {
// If something goes wrong, print an error message.
if(err) {
console.log(err.message);
} else {
console.log("Email sent! Message ID: ", data.MessageId);
}
});
html 文件
<html>
<head></head>
<body>
<h1>Amazon SES Test</h1>
<p>Your order is placed.
<a href='https://example.com/id=1234125'>View your order</a>
</p>
</body>
</html>
我的问题:如何将 href 作为变量从 nodejs 文件传递到 html 文件。
欢迎任何建议。
您可以在 HTML 中使用占位符,例如:<a href="HREF_PLACEHOLDER">...</a>
.
然后在 HTML 上使用 string.replace() 将其替换为您想要的实际 href。
例如:
function dynamicHtml(href) {
return HTML.replace("HREF_PLACEHOLDER", href);
}
而不是将 HTML 传递给您的参数对象,而是将其传递 dynamicHtml()