电子邮件模板变量会自动成为锚链接吗?

时间:2018-05-09 19:51:22

标签: javascript nodemailer

我正在做一个非常简单的联系表单,我正在捕获表单数据并将其发送到电子邮件。我的问题是,当我在表单中捕获req.body.email变量并将其发送到电子邮件时,它会自动创建一个我没有创建的<a></a>标记。我试图通过设置text-decoration:none;color:#fff !important;来消除电子邮件变量上的蓝色,但我发送到我的电子邮件的电子邮件变量仍然是蓝色的,因为锚标记是动态生成的我不能在我的模板中做任何内联样式?有没有办法在动态创建的电子邮件中更改蓝色?

这是我的代码:

型号:

var contactMail = require('./Contactmail');
var nodemailer = require('nodemailer');
var inlineCss = require('nodemailer-juice');

var contact = {
    contactsendEmail: function (data, callback) {
        var transporter = nodemailer.createTransport({
            service: 'gmail',
            auth: {
                user:'...',
                pass:'...'
            },
            tls: {
                rejectUnauthorized: false
            }
        });
        var mailOptions = {
            from: 'test@test.com',
            to: 'johnsmith@test.com',
            subject: 'Form Submission Results',
            html: contactMail.contactTemplate(data)
        };
        transporter.use('compile',inlineCss(mailOptions));
        transporter.sendMail(mailOptions, callback, function(error, info){
            if(error){
                return console.log(error);
            } else {
                return console.log('Message sent: ' + info.response);
            }
        });
    }
}

module.exports = contact;

电子邮件模板:

var contactMail = {
    contactTemplate: function(data){
        var getYear = new Date().getFullYear('yyyy');

        var message = '';
            message += "<!doctype html>"
            message += "<html>"
            message += "<head>"
            message += "<title>"
            message += "Form Submission Results"
            message += "</title>"
            message += "<!--[if !mso]><!-- -->"
            message += "<meta http-equiv='X-UA-Compatible' content='IE=edge'>"
            message += "<!--<![endif]-->"
            message += "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>"
            message += "<meta name='viewport' content='width=device-width, initial-scale=1'>"
            message += "<style type='text/css'>"
            message += "#outlook a {padding: 0;}"
            message += ".ReadMsgBody {width: 100%;}"
            message += ".ExternalClass {width: 100%;}"
            message += ".ExternalClass * {line-height: 100%;}"
            message += "body {margin: 0;padding: 0;-webkit-text-size-adjust: 100%;-ms-text-size-adjust: 100%;}"
            message += "table,td {border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;}"
            message += "img {border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;}"
            message += "p {display: block;margin: 13px 0;}"
            message += "</style>"
            message += "<!--[if !mso]><!-->"
            message += "<style type='text/css'>"
            message += "@media only screen and (max-width:480px) {@-ms-viewport {width: 320px;}@viewport {width: 320px;}}"
            message += "</style>"
            message += "<style type='text/css'>@media only screen and (min-width:480px) {.mj-column-per-100 {width: 100% !important;}}"
            message += "</style>"
            message += "</head>"
            message += "<body style='background-color:#F4F4F4;'>"
            message += "<div style='background-color:#F4F4F4;'>"
            message += "<!--[if mso | IE]>"
            message += "<table align='center' border='0' cellpadding='0' cellspacing='0' style='width:600px;' width='600'>"
            message += "<tr>"
            message += "<td style='line-height:0px;font-size:0px;mso-line-height-rule:exactly;'>"
            message += "<![endif]-->"
            message += "<div style='background:#000000;background-color:#000000;Margin:0px auto;max-width:600px;'>"
            message += "<table align='center' border='0' cellpadding='0' cellspacing='0' role='presentation' style='background:#000000;background-color:#000000;width:100%;'>"
            message += "<tbody>"
            message += "<tr>"
            message += "<td style='direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;'>"
            message += "<!--[if mso | IE]>"
            message += "<table role='presentation' border='0' cellpadding='0' cellspacing='0'>"
            message += "<tr>"
            message += "<td style='vertical-align:top;width:600px;'>"
            message += "<![endif]-->"
            message += "<div class='mj-column-per-100 outlook-group-fix' style='font-size:13px;text-align:left;direction:ltr;display:inline-block;vertical-align:top; 'width:100%;'>"
            message += "<table border='0' cellpadding='0' cellspacing='0' role='presentation' style='vertical-align:top;' width='100%'>"
            message += "<tr>"
            message += "<td align='center' style='font-size:0px;padding:10px 25px;word-break:break-word;'>"
            message += "<table align='center' border='0' cellpadding='0' cellspacing='0' role='presentation' style='border-collapse:collapse;border-spacing:0px;'>"
            message += "<tbody>"
            message += "<tr>"
            message += "<td style='width:180px;'>"
            message += "<img height='auto' src='http://5vph.mj.am/img/5vph/b/1g86w/0g67t.png' style='border:none;display:block;outline:none;text-decoration:none;width:100px;'/>"
            message += "</td>"
            message += "</tr>"
            message += "</tbody>"
            message += "</table>"
            message += "</td>"
            message += "</tr>"
            message += "</table>"
            message += "</div>"
            message += "<!--[if mso | IE]>"
            message += "</td>"
            message += "</tr>"
            message += "</table>"
            message += "<![endif]-->"
            message += "</td>"
            message += "</tr>"
            message += "</tbody>"
            message += "</table>"
            message += "</div>"
            message += "<!--[if mso | IE]>"
            message += "</td>"
            message += "</tr>"
            message += "</table>"
            message += "<table align='center' border='0' cellpadding='0' cellspacing='0' style='width:600px;' width='600'>"
            message += "<tr>"
            message += "<td style='line-height:0px;font-size:0px;mso-line-height-rule:exactly;'>"
            message += "<![endif]-->"
            message += "<div style='background:#000000;background-color:#000000;Margin:0px auto;max-width:600px;'>"
            message += "<table align='center' border='0' cellpadding='0' cellspacing='0' role='presentation' style='background:#000000;background-color:#000000;width:100%;'>"
            message += "<tbody>"
            message += "<tr>"
            message += "<td style='direction:ltr;font-size:0px;padding:0 0 0 0;text-align:center;vertical-align:top;'>"
            message += "<!--[if mso | IE]>"
            message += "<table role='presentation' border='0' cellpadding='0' cellspacing='0'>"
            message += "<tr>"
            message += "<td style='vertical-align:top;width:600px;'>"
            message += "<![endif]-->"
            message += "<div class='mj-column-per-100 outlook-group-fix' style='font-size:13px;text-align:left;direction:ltr;display:inline-block;width:100%;vertical-align:top;'>"
            message += "<table border='0' cellpadding='0' cellspacing='0' role='presentation' style='vertical-align:top;width:100%;'>"
            message += "<tr>"
            message += "<td align='left' style='font-size:0px;padding:10px 25px;padding-top:25px;padding-bottom:5px;word-break:break-word;'>"
            message += "<div style='font-size:13px;line-height:22px;text-align:left;color:#55575d;'>"
            message += "<p style='line-height: 60px; text-align: center; margin: 10px 0;font-size:35px;color:#fcfcfc;'><b>Form Submission Results</b></p>"
            message += "</div>"
            message += "</td>"
            message += "</tr>"
            message += "<tr>"
            message += "<td align='left' style='font-size:0px;padding:10px 25px;word-break:break-word;'>"
            message += "<div style='font-size:13px;line-height:1;text-align:left;color:#000000;'>"
            message += "<p style='color: #fff; font-size:16px;'>Fullname: <span style='color:#ccc;'>"+data.fullName+"</span></p>"
            message += "<p style='color: #fff; font-size:16px;'>Email: <span style='color:#ccc;'>"+data.email+"</span></p>"
            message += "<p style='color: #fff; font-size:16px;'>Subject: <span style='color:#ccc;'>"+data.subject+"</span></p>"
            message += "<p style='color: #fff; font-size:16px;'>Message: <span style='color:#ccc;line-height:24px;'>"+data.message+"</span></p>"
            message += "</div>"
            message += "</td>"
            message += "</tr>"
            message += "</table>"
            message += "</div>"
            message += "<!--[if mso | IE]>"
            message += "</td>"
            message += "</tr>"
            message += "</table>"
            message += "<![endif]-->"
            message += "</td>"
            message += "</tr>"
            message += "</tbody>"
            message += "</table>"
            message += "</div>"
            message += "<!--[if mso | IE]>"
            message += "</td>"
            message += "</tr>"
            message += "</table>"
            message += "<table align='center' border='0' cellpadding='0' cellspacing='0' style='width:600px;' width='600'>"
            message += "<tr>"
            message += "<td style='line-height:0px;font-size:0px;mso-line-height-rule:exactly;'>"
            message += "<![endif]-->"
            message += "<div style='background:#000000;background-color:#000000;Margin:0px auto;max-width:600px;'>"
            message += "<table align='center' border='0' cellpadding='0' cellspacing='0' role='presentation' style='background:#000000;background-color:#000000;width:100%;'>"
            message += "<tbody>"
            message += "<tr>"
            message += "<td style='direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;'>"
            message += "<!--[if mso | IE]>"
            message += "<table role='presentation' border='0' cellpadding='0' cellspacing='0'>"
            message += "<tr>"
            message += "<td style='vertical-align:top;width:600px;'>"
            message += "<![endif]-->"
            message += "<div class='mj-column-per-100 outlook-group-fix' style='font-size:13px;text-align:left;direction:ltr;display:inline-block;vertical-align:top; width:100%;'>"
            message += "<table border='0' cellpadding='0' cellspacing='0' role='presentation' style='vertical-align:top;' width='100%'>"
            message += "<tr>"
            message += "<td align='left' style='font-size:0px;padding:10px 25px;word-break:break-word;'>"
            message += "<div style='font-family:Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#55575d;'>"
            message += "<p style='line-height: 16px; text-align: center; margin: 10px 0;font-size:12px;color:#ffffff;font-family:Arial,Helvetica,sans-serif;'>&copy; "+getYear+" John<span style='color:#ccc;'> Smith</span></p>"
            message += "</div>"
            message += "</td>"
            message += "</tr>"
            message += "</table>"
            message += "</div>"
            message += "<!--[if mso | IE]>"
            message += "</td>"
            message += "</tr>"
            message += "</table>"
            message += "<![endif]-->"
            message += "</td>"
            message += "</tr>"
            message += "</tbody>"
            message += "</table>"
            message += "</div>"
            message += "<!--[if mso | IE]>"
            message += "</td>"
            message += "</tr>"
            message += "</table>"
            message += "<![endif]-->"
            message += "</div>"
            message += "</body>"
            message += "</html>"
        return message;
    }
}

module.exports = contactMail;

我收到的电子邮件结果的屏幕截图:

enter image description here

0 个答案:

没有答案