2015-02-03 5 views
9

ईमेल संलग्नक भेजना अभी तक उल्का के आधिकारिक email package में लागू नहीं किया जा रहा है। मैंने nodemailer सुझाव (here देखा) की कोशिश की है, लेकिन त्रुटि को प्राप्त नहीं किया गया है "संपत्ति को पढ़ नहीं सकता है" अपरिभाषित के ट्रान्सपोर्ट '।Meteor.js (ईमेल पैकेज और/या नोडमेलर या अन्यथा) के साथ ईमेल अनुलग्नक भेजना

मैं डेटा यूआरआई में एक CSV फ़ाइल बनाने का प्रयास कर रहा हूं और फिर उस अनुलग्नक को भेजता हूं। यहाँ मेरी कोड का एक टुकड़ा है जब आधिकारिक ईमेल पैकेज का उपयोग:

csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv); 

var options = { 
      from: "[email protected]", 
      to: "[email protected]", 
      subject: "xxx", 
      html: html, 
      attachment: { 
      fileName: fileName, 
      path: csvData 
      } 
     }; 

Meteor.call('sendEmail', options); 

संपादित करें:

यहाँ क्या मेरी nodemailer कोड की तरह दिखाई देता मूल रूप से है:

var nodemailer = Nodemailer; 
var transporter = nodemailer.createTransport(); 
transporter.sendMail({ 
    from: '[email protected]', 
    to: '[email protected]', 
    subject: 'hello', 
    text: 'hello world!', 
    attachments: [ 
     { 
      path: csvData 
     } 
    ] 
}); 
+0

क्या nodemailer कोड आप की कोशिश की है? मुझे विश्वास नहीं है कि अनुलग्नक उल्का आधिकारिक पैकेज में समर्थित हैं। – rivarolle

+0

मैंने [इस पैकेज] (https://atmospherejs.com/mrt/meteor-nodemailer) का उपयोग किया और इसे चलाने के लिए निर्देशों का पालन किया (उल्का के ईमेल में बहुत समान सेटअप है)। मैं कोड के साथ अपना प्रश्न अपडेट करूंगा। –

+0

इस आलेख में कुछ उदाहरण हैं http://kukuruku.co/hub/javascript/meteor-how-to-build-a-todo-list –

उत्तर

5

पर्याप्त प्रतिनिधि टिप्पणी करने के लिए।

मैंने सेंडग्रिड्स एनपीएम पैकेज का उपयोग करके अनुलग्नक समस्या को हल करने का अंत किया।

npm install sendgrid 

यदि आपके पास उल्का ऐप में एनपीएम नहीं है तो आप इसे पढ़ सकते हैं। https://meteorhacks.com/complete-npm-integration-for-meteor

अपने packages.json

{ 
    "sendgrid": "1.4.0" 
} 
फिर उस सर्वर पर चलाता है एक फ़ाइल में

में:

Meteor.startup(function(){ 
    process.env.MAIL_URL = 'smtp://<username>:<password>@smtp.sendgrid.net:587'; 
}); 

यहां नमूने उल्का विधि (हम चाहते हैं कि एक लगाव का यूआरएल हो जाता है एक अनुलग्नक संग्रह से 'एस 3 का उपयोग कर रहे हैं)। यह विशेष विधि प्राप्तकर्ताओं की किसी भी संख्या में अनुलग्नकों की संख्या भेज सकती है। यहां कुछ संदर्भ विशिष्ट तर्क हैं लेकिन यह आपको प्राप्त करने और अनुलग्नक भेजने के लिए पर्याप्त होना चाहिए।

महत्वपूर्ण हिस्सा:

var email = new sendgrid.Email(); 
email.setFrom("[email protected]"); 
email.setSubject("subject"); 
email.addFile({ 
    filename: attachment_name, 
    url: attachment_url 
}); 
sendgrid.send(email, function (err, json) { 
    if (err) { 
     console.error(err); 
    } 
    if (json) { 
     console.log(json.message);     
    } 
}); 

एक पूरा विधि उदाहरण:

Meteor.methods({ 
SendEmail: function (subject, message, templateNumber) { 

    //console.log(subject, message, templateNumber); 

    var user_id = Meteor.userId(); 
    var list = UserList.find({user_id: user_id}).fetch(); 
    var sentTemplate = sentTemplate + templateNumber; 
    var counter = 0; 
    console.log(list.length); 
    // Track is the 'No Response' from the list. 
    for (var i = 0; i < list.length; i++) {  
      var email = new sendgrid.Email(); 
      if (list[i].track == null || list[i].track == "1") { 
       //email.addTo(list[0].list[i].Email); 
       //console.log(list[0].list[i].Email); 
       email.to = list[i].email; 
      } 
      email.setFrom(Meteor.user().email); 
      email.replyto = Meteor.user().email; 

      email.setSubject(subject); 

      var firstName = list[i].name.split(" ")[0]; 

      var companyReplace = message.replace("{{Company}}", list[i].company).replace("{{Company}}", list[i].company).replace("{{Company}}", list[i].company).replace("{{Company}}", list[i].company).replace("{{Company}}", list[i].company); 
      var nameReplace = companyReplace.replace("{{Name}}",list[i].name).replace("{{Name}}",list[i].name).replace("{{Name}}",list[i].name).replace("{{Name}}",list[i].name).replace("{{Name}}",list[i].name) 
      var firstNameReplace = companyReplace.replace("{{FirstName}}",firstName).replace("{{FirstName}}",firstName).replace("{{FirstName}}",firstName).replace("{{FirstName}}",firstName).replace("{{FirstName}}",firstName); 

      email.setHtml(firstNameReplace); 

      var numAttachments = Attachments.find({user_id: Meteor.userId()}).fetch().length; 
      var attachments = Attachments.find({user_id: Meteor.userId()}).fetch(); 
      console.log("**********Attachments****************"); 
      console.log(attachments); 
      console.log("**********Attachments****************"); 
      for (var t = 0; t < numAttachments; t++) { 
       email.addFile({ 
        filename: attachments[t].attachment_name, 
        url: attachments[t].attachment_url 
       }); 
      } 
      sendgrid.send(email, function (err, json) { 
       if (err) { 
        console.error(err); 
       } 
       if (json) { 
        console.log(json.message); 

       } 
      }); 
      //console.log(email); 

    } // end for loop 

    if (templateNumber == 1) { 
     Meteor.users.update({_id:Meteor.userId()}, {$set: {"sentTemplate1": true}}); 
    } 
    if (templateNumber == 2) { 
     Meteor.users.update({_id:Meteor.userId()}, {$set: {"sentTemplate2": true}}); 
    } 
    if (templateNumber == 3) { 
     Meteor.users.update({_id:Meteor.userId()}, {$set: {"sentTemplate3": true}}); 
    } 
    if (templateNumber == 4) { 
     Meteor.users.update({_id:Meteor.userId()}, {$set: {"sentTemplate4": true}}); 
    } 
    // for each email. replace all html 

    return list.length; 
} 
}); 
संबंधित मुद्दे