2014-11-04 32 views
0

你好, 我試圖用附件發送電子郵件,使用發送郵件帶有附件的使用AWS-SDK(亞馬遜SES)使用的NodeJS

var params = { 
     RawMessage: { 
      From: "[email protected]", 
      To: "[email protected]", 
      Date: new Date(), 
      Subject: "Hello", 
      "Accept-Language": "en-US", 
      "Content-Language": "en-US", 
      "Content-Type": "text/plain", charset: "us-ascii", 
      "Content-Transfer-Encoding": "quoted-printable", 
      "MIME-Version": 1.0, 
      Data: "Hello, I hope you are having a good day." 
     }, 
     Destinations: [ 
      "[email protected]" 
     ], 
     Source: "[email protected]" 
    }; 

    ses.sendRawEmail(params, function (err, data) { 
     if (err) console.log("err>>" + err, err.stack); // an error occurred 
     else  console.log("data>>>" + JSON.stringify(data));   // successful response 
    }); 

,但我得到的錯誤

UnexpectedParameter: UnexpectedParameter:在params.RawMessage中發現意外的密鑰'To' *意外的參數:在params.RawMessage中發現意外的密鑰'Date' * UnexpectedParameter:Unexpected關鍵'主題'發現在params.RawMessage *意外的參數:在params.RawMessage中發現意外的鍵'接受語言' *意外的參數:在params.RawMessage中發現意外的鍵'內容語言' *意外的參數:意外的鍵'類型'在params.RawMessage中找到 *意外的參數:在params.RawMessage中發現意外的鍵'charset' * UnexpectedParameter:在params.RawMessage中發現意外的鍵'Content-Transfer-Encoding' *意外的參數:意外的鍵'MIME-Version'發現在params.RawMessage

我知道我沒有使用正確的參數格式,但我沒有得到正確的格式在任何地方,請幫助我.... 。 在此先感謝...

回答

1

According to the documentation,現場RawMessage只包含Data財產而已。 Data字段包含完整的原始電子郵件消息 - 包括正確格式(轉義,編碼)和分隔符(正確數量的換行符)的標題和正文(或正文)。

您可能正在尋找sendEmail,它允許您將「To」,「From」和「Subject」字段設置爲key-value對。

+0

感謝RikkusRukkus,您能否詳細通知我數據應包含哪些內容,我需要發送帶附件的電子郵件,如果可能的話包含多個to,cc和bcc以及我必須寫主題的地方,使用Nodejs來做到這一點,請幫助我,謝謝 – 2014-11-04 17:01:16

+2

'數據'應該是*整個*電子郵件的緩衝區。這意味着你首先設置標題,雙換行符,然後設置正文。只需使用[mailcomposer](https://github.com/andris9/mailcomposer)即可。它使你的生活更輕鬆。輸出'mailcomposer.buildMessage'可以直接注入'Data'。 – RikkusRukkus 2014-11-05 09:03:20

+0

謝謝RikkusRukkus,我已經獲得了很多與您的鏈接,但仍然有2概率,第一我不能從我的系統附加文件,第二我已經要求寫入內容到文件,然後從文件讀取,然後將此給RawMessage- - > data,mailcomposer.addAttachment({//這是行不通的 fileName:「serv.txt」, filePath:「./cust-serv.txt」 }); mailcomposer.streamMessage(); mailcomposer.pipe(fs.createWriteStream(「testnew.eml」)); fs.readFile( 'testnew.eml',函數(ERR,數據){ 如果(ERR){..} PARAMS = { RawMessage:{ 數據:數據 }, ....... ..... – 2014-11-05 14:21:23

相關問題