使用IMAP / SMTP在Gmail中创建邮件(即草稿)? [英] Creating messages (ie drafts) in Gmail with IMAP/SMTP?

查看:159
本文介绍了使用IMAP / SMTP在Gmail中创建邮件(即草稿)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过PHP中的IMAP函数使用Gmail对Gmail进行了相当多的收件箱操作,但有一件事我没有找到,它是创建邮件的一种方式。我不确定是否需要IMAP或SMTP,但我希望使用PHP创建一条存储在我的收件箱中的新邮件(特别是一份草稿),并准备在稍后的日期发送一切内容。我该如何解决这个问题?

你可能想看看 imap_mail_compose()
$ b strong>
这不会在服务器上创建消息。您还需要使用imap_append()。



进一步编辑
这似乎工作正常:

 <?php 
$ rootMailBox ={imap.gmail.com:993/imap/ssl};
$ draftsMailBox = $ rootMailBox。 '[Google Mail] /草稿';

$ conn = imap_open($ rootMailBox,sdfsfd@gmail.com,password)或die(无法连接:。imap_last_error());

$ envelope [to] =test@test.com;
$ envelope [subject] =测试草稿;

$ part [type] = TYPETEXT;
$ part [subtype] =plain;
$ part [description] =零件描述;
$ part [contents.data] =测试内容;

$ body [1] = $ part;

$ msg = imap_mail_compose($ envelope,$ body);
$ b $ if(imap_append($ conn,$ draftsMailBox,$ msg)=== false){
die(could not append message:。imap_last_error());
}


I've done quite a bit of inbox manipulation with Gmail via IMAP functions in PHP, but one thing I haven't found is a way to create messages. I'm not sure if IMAP or SMTP is required, but I would like to use PHP to create a new message (specifically a draft) that is stored in my inbox with everything ready to hit send at a later date. How do I go about this?

解决方案

You might want to look at imap_mail_compose()

Edit This doesn't create the message on the server. You need to use imap_append() also.

Further Edit This seems to work ok:

<?php 
$rootMailBox = "{imap.gmail.com:993/imap/ssl}";
$draftsMailBox = $rootMailBox . '[Google Mail]/Drafts';

$conn = imap_open ($rootMailBox, "sdfsfd@gmail.com", "password") or die("can't connect: " . imap_last_error());

$envelope["to"]  = "test@test.com";
$envelope["subject"]  = "Test Draft";

$part["type"] = TYPETEXT;
$part["subtype"] = "plain";
$part["description"] = "part description";
$part["contents.data"] = "Testing Content";

$body[1] = $part;

$msg = imap_mail_compose($envelope, $body);

if (imap_append($conn, $draftsMailBox, $msg) === false) {
        die( "could not append message: " . imap_last_error() )  ;
}

这篇关于使用IMAP / SMTP在Gmail中创建邮件(即草稿)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆