Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在reactjs中使用gmail api发送包含纯文本、附件和html的电子邮件_Javascript_Reactjs_Email_Gmail_Gmail Api - Fatal编程技术网

Javascript 在reactjs中使用gmail api发送包含纯文本、附件和html的电子邮件

Javascript 在reactjs中使用gmail api发送包含纯文本、附件和html的电子邮件,javascript,reactjs,email,gmail,gmail-api,Javascript,Reactjs,Email,Gmail,Gmail Api,我目前正在尝试使用reactjs中的gmail api发送包含3个组件的电子邮件:纯文本、附件和html。现在使用我的代码发送电子邮件,我只能接收附件和html。下面是我用来发送电子邮件的代码: for (i=0; i<email.attachment.length; i++) { let content = email.attachment[i].data.split(",")[1]; let attachment = ['--

我目前正在尝试使用reactjs中的gmail api发送包含3个组件的电子邮件:纯文本、附件和html。现在使用我的代码发送电子邮件,我只能接收附件和html。下面是我用来发送电子邮件的代码:

    for (i=0; i<email.attachment.length; i++) {
        let content = email.attachment[i].data.split(",")[1];
        let attachment = ['--012boundary01\r\n',
                         'Content-Type: ' + email.attachment[i].type + '\r\n',
                         'MIME-Version: 1.0\r\n',
                         'Content-Transfer-Encoding: base64\r\n',
                         'Content-Disposition: attachment; filename=' + email.attachment[i].name + '\r\n\r\n',
                          content, '\r\n\r\n'].join('');
        console.log(attachment)
        attachments += attachment
     };

     let mail = [
        'Content-Type: multipart/mixed; boundary="012boundary01"\r\n',
        'MIME-Version: 1.0\r\n',
        'To: ' + email.to + '\r\n',
        'Subject: ' + email.subject + '\r\n\r\n',
        '--012boundary01\r\n',
        'Content-Type: multipart/alternative; boundary=012boundary02\r\n\r\n',
        '--012boundary02\r\n',
        'Content-Type: text/plain; charset=UTF-8\r\n\r\n',
        email.body + '\r\n\r\n',
        '--012boundary02\r\n',
        'Content-Type: text/html; charset=UTF-8\r\n',
        'Content-Transfer-Encoding: quoted-printable\r\n\r\n',
        '<h1>HELLO</h1>\r\n\r\n',
        '--012boundary02--\r\n',

        attachments,

        '--012boundary01--'
     ].join('');
for(i=0;i答案:
您的纯文本正在被发送,但您的邮件应用程序能够显示HTML,因此您无法看到它

更多信息: 电子邮件的纯文本部分显示在电子邮件客户端中,无法显示更复杂的内容,在您的例子中,是HTML

如果您转到Gmail用户界面并查看原始消息,请按照
⋮ > 在信息的右上角显示原始信息
,您将看到您的纯文本在信息中的原样

由于您也有HTML,所以可以显示HTML的电子邮件客户端将显示它而不是纯文本,而不是在它旁边

您的代码运行良好,如果您想要查看纯文本,则需要使用非HTML显示客户端,或者从消息中删除HTML


我希望这对你有帮助!

你的问题是什么?当我像这样发送电子邮件时,只有html和附件被发送。纯文本没有显示在电子邮件中。所以我的问题是我的代码有什么问题,为什么纯文本没有发送和显示在电子邮件中。谢谢你的回答。我决定将纯文本包装起来将ext改为html,现在工作正常。谢谢!
Content-Type: multipart/mixed; boundary="012boundary01"

MIME-Version: 1.0

To: angyangcheng99@gmail.com

Subject: test again

--012boundary01
Content-Type: multipart/alternative; boundary=012boundary02

--012boundary02
Content-Type: text/plain; charset=UTF-8

testing123

--012boundary02

Content-Type: text/html; charset=UTF-8

Content-Transfer-Encoding: quoted-printable

<h1>HELLO</h1>

--012boundary02--

--012boundary01

Content-Type: image/jpeg

MIME-Version: 1.0

Content-Transfer-Encoding: base64

Content-Disposition: attachment; filename=1x1_red_pixel.jpeg

(base64 encoded string here)