2015-06-02 9 views
6

मैं जावास्क्रिप्ट के साथ गूगल एपीआई के माध्यम से एक ईमेल भेजने के कोशिश कर रहा हूँ के साथ गूगल एपीआई के माध्यम से मेल भेजने में विफल।जावास्क्रिप्ट

'raw' RFC822 payload message string or uploading message via /upload/* URL required`

मेरे कोड

function sendMessage() { 
gapi.client.load('gmail', 'v1', function() { 
    // Web-safe base64 
    var to = '[email protected]', 
     subject = 'Hello World', 
     content = 'send a Gmail.' 

    var base64EncodedEmail = btoa(
      "Content-Type: text/plain; charset=\"UTF-8\"\n" + 
      "Content-length: 5000\n" + 
      "Content-Transfer-Encoding: message/rfc2822\n" + 
      "to: [email protected]\n" + 
      "from: \"test\" <[email protected]>\n" + 
      "subject: Hello world\n\n" + 

      "The actual message text goes here" 
      ).replace(/\+/g, '-').replace(/\//g, '_'); 

    var mail= base64EncodedEmail; 
    console.log(mail); 
    var request = gapi.client.gmail.users.messages.send({ 
     'userId': "me", 
     'message': { 
      'raw': mail 
     } 
    }); 
    request.execute(function(response){ 
    console.log(response); 
    }); 
    });   

} 
+0

संबंधित: http://stackoverflow.com/questions/34546142/gmail-api-for-sending-mails-in-node -js/ – Sergio

+0

आप (,/\ +/जी '-') व्याख्या कर सकते हैं कृपया क्यों 'की जगह की जगह (/ \ // जी, '_')' '••• साथ' + 'जगह -' और' /। '_' के साथ? '' ' –

उत्तर

12

दिनों के बाद मैं द्वारा जवाब मिल गया था:

मेरे मुद्दा यह है कि जब मैं कोई संलग्नक के साथ एक सरल मेल भेजने के लिए प्रयास करते हैं, मैं निम्नलिखित त्रुटि मिलती है मेरा अपना। समस्या यह थी कि जब आप ईमेल में अनुलग्नक भेजते हैं तो केवल शरीर में 'संदेश' का उपयोग किया जा सकता है।

आप कोई लगाव है, तो जैसे मैं यहाँ नीचे लिखा क्वेरी लग रहा है

var mail= base64EncodedEmail; 
console.log(mail); 
var request = gapi.client.gmail.users.messages.send({ 
    'userId': "me", 
    'resource': { 
     'raw': mail 
    } 
}); 
request.execute(function(response){ 
console.log(response); 
}); 
+0

से बचने से बचने के लिए '' '(एकल उद्धरण) को सरल बनाने के लिए धन्यवाद। धन्यवाद। – maxm

+0

धन्यवाद! मुझे यह असंगत लगता है कि' ड्राफ्ट.क्रेट''' और '' 'message.send''' एक ही वाक्यविन्यास का उपयोग नहीं कर रहे हैं ... –

+0

इस के लिए एक अजगर संस्करण है? – paradox

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