2015-09-23 5 views
5

मैं nodemailer और node.js का उपयोग करके एक पीडीएफ दस्तावेज संलग्न करना चाहता हूं, हालांकि, नोडमेलर के साथ अनुलग्नकों के लिए मुझे मिल रहे एकमात्र उदाहरण हैं .txt फ़ाइलें (here) के साथ।नोड.जेएस और नोडेमेलर: क्या हम ईमेल पर पीडीएफ दस्तावेज़ संलग्न कर सकते हैं?

क्या किसी को पता है कि पीडीएफ दस्तावेज़ अनुलग्नक को नोडमेलर के साथ समर्थित किया गया है?

प्रारंभ में ऐसा लगता है कि एक पीडीएफ संलग्न किया जा सकता है, फिर भी ईमेल के माध्यम से आने वाली पीडीएफ फाइल क्षतिग्रस्त हो जाती है (छवि देखें)।

enter image description here

कोड: (महेश के जवाब से अनुकूलित)

fs.readFile('/filePath/fileName.pdf', function (err, data) { 
if (err) throw err;             
var mailOptions = { 
    from: 'Test <[email protected]>', // sender address         
    to: 'toPersonName <[email protected]>', // list of receivers         
    subject: 'Attachment', // Subject line             
    text: 'Hello world attachment test', // plaintext body             
    html: '<b>Hello world attachment test HTML</b>', // html body            
    attachments: [ 
     { 
      filename: 'fileName.pdf',           
      contentType: 'application/pdf' 
     }] 
}; 

// send mail with defined transport object             
transporter.sendMail(mailOptions, function(error, info){ 
    if(error){ 
     return console.log(error); 
    } 
    console.log('Message sent: ' + info.response); 
}); 
console.log(data); 
}); 

टर्मिनल प्रतिक्रिया:

<Buffer 25 50 44 46 2d 31 2e 33 0a 25 c4 e5 f2 e5 eb a7 f3 a0 d0 c4 c6 0a 34 20 30 20 6f 62 6a 0a 3c 3c 20 2f 4c 65 6e 67 74 68 20 35 20 30 20 52 20 2f 46 69 ... > 
Message sent: 250 2.0.0 OK 1443026036 hq8sm3016566pad.35 - gsmtp 
+0

यह AFAIK सभी गैर-पाठ सामग्री-प्रकार – prasun

उत्तर

9

हाँ आप कर सकते हैं। आपको उस फ़ाइल का पथ जोड़ना होगा जिसे आप संलग्न करने का प्रयास कर रहे हैं।

transporter.sendMail({ 
    from: '[email protected]'. 
    to: '[email protected]', 
    subject: 'an attached file', 
    text: 'check out this attached pdf file', 
    attachments: [{ 
    filename: 'file.pdf', 
    path: 'C:/Users/Username/Desktop/somefile.pdf' 
    contentType: 'application/pdf' 
    }], function (err, info) { 
    if(err){ 
     console.error(err); 
     res.send(err); 
    } 
    else{ 
     console.log(info); 
     res.send(info); 
    } 
    } 
); 
+0

आप लोगों को अपने PDF को अपलोड और देते हैं अनुमति देने के लिए कैसे खाते हैं का समर्थन करता है? 'पथ' क्या होगा? – Growler

+0

क्षमा करें, मैं आपको नहीं मिला। – Vishnu

+0

यह https://nodemailer.com/message/attachments/ जांचें – Vishnu

संबंधित मुद्दे