我使用NodeMailer创建了以下功能,它似乎正在发送没有问题的电子邮件("发送消息"收到控制台和电子邮件中的通知),除了没有发送任何电子邮件的附件!
尝试了一堆电子邮件地址(gmail,谷歌应用程序,hotmail),但所有人都在做同样的事情。请帮忙!
var sendWithAttachment = function(userMail, subject, html, attachment_path, cb){
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "labs@domain.com",
pass: "password"
}
});
var mailOptions = {
from: "Labs <labs@domain.com>",
to: userMail,
subject: subject || "[blank]"
html: html || "[none]"
generateTextFromHTML: true,
attachments: [
{ // filename and content type is derived from path
path: attachment_path
},
{ // utf-8 string as an attachment
filename: 'check.txt',
content: 'checking that some attachments work...'
},
],
};
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
cb(error, null);
}else{
console.log("Message sent: " + response.message);
cb(null, response);
}
smtpTransport.close();
});
};
答案 0 :(得分:9)
这是nodemailer文档中的一个问题。使用“filePath”更改“路径”以定义路径并将“内容”更改为文本的“内容”。为我工作。
var mailOptions = {
...
attachments: [
{ // utf-8 string as an attachment
filename: 'text1.txt',
contents: 'hello world!'
},
{ // utf-8 string as an attachment
filename: 'text1.txt',
filePath: 'text.txt'
},
]
}
答案 1 :(得分:4)
我通过将content
重命名为contents
来解决了这个问题。我正在阅读最新版nodemailer
的最新文档。您可以在此处阅读小于 1.0 的版本的文档:https://github.com/andris9/Nodemailer/blob/0.7/README.md
答案 2 :(得分:0)
bool validRam =
(m_RAMSize+m_ramSuffix) == "4GB" ||
(m_RAMSize+m_ramSuffix) == "8GB" ||
(m_RAMSize+m_ramSuffix) == "16GB" ||
(m_RAMSize+m_ramSuffix) == "32GB";
bool validID = (m_idNumber >= MIN_ID && m_idNumber <= MAX_ID);
...
return validRam && validID && validType && validLocation && validDisk;
答案 3 :(得分:0)
//由nodemailer发送带有附件的电子邮件的简单代码
private void cmdDeleteLetter_Click(object sender, RoutedEventArgs e)
{
var selectedItem = (Letter)lstLetters.SelectedItem;
_client.DeleteLetter(selectedItem);
_letters.Remove(selectedItem);
}
private void cmdAddLetter_Click(object sender, RoutedEventArgs e)
{
var newLetter = new Letter
{
Name = "Letter3",
Date = DateTime.Now,
Recipient = "John",
Sender = "David",
Content = "cccc"
};
_client.AddNewLetter(newLetter);
_letters.Add(newLetter);
}