简体   繁体   English

如何使用 IMAP 使用 GO 在 Gmail 中创建草稿

[英]How do I create a draft in Gmail using IMAP using GO

I would like to use GO to create a new message ( specifically a draft ) that is stored in my inbox with everything ready to hit send at a later date.我想使用 GO 创建一条新消息(特别是草稿),该消息存储在我的收件箱中,所有内容都可以在以后发送。 With SMTP I think it won't work.使用 SMTP 我认为它不起作用。 With IMAP maybe I can.使用 IMAP 也许我可以。 How do I go about this?我该如何 go 关于这个?

package main

import (
    "bytes"
    "log"
    "os"
    "time"

    "github.com/emersion/go-imap"
    "github.com/emersion/go-imap/client"
)

func main() {
    log.Println("Connecting to server...")

    // Connect to server
    c, err := client.DialTLS(os.Getenv("IMAP_SERVER"), nil)
    if err != nil {
        log.Fatal(err)
    }
    log.Println("Connected")

    // Don't forget to logout
    defer c.Logout()

    // Login
    if err := c.Login(os.Getenv("IMAP_USER"), os.Getenv("IMAP_PASSWORD")); err != nil {
        log.Fatal(err)
    }
    log.Println("Logged in")

    // Write the message to a buffer
    var b bytes.Buffer
    b.WriteString("From: <...@gmail.com>\r\n")
    b.WriteString("To: <...@gmail.com>\r\n")
    b.WriteString("Subject: Append test\r\n")
    b.WriteString("\r\n")
    // Message body
    b.WriteString("Append test using Gmail IMAP and Draft folder")

    // Append it to Drafts
    if err := c.Append("[Gmail]/Drafts", nil, time.Now(), &b); err != nil {
        log.Fatal(err)
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Python 创建/管理 GCP API 密钥 - How do I create/manage GCP API keys using Python 如何使用 UNION ALL function 在 SQL 中创建新表? - How do I create a new table in SQL with using the UNION ALL function? 如何使用 AWS CodePipeline 为 Laravel 应用程序正确创建 buildspec.yml 文件 - How do I properly create buildspec.yml file for Laravel Application using AWS CodePipeline 如何创建预签名 URL 以使用 Boto3 从 S3 存储桶下载文件? - How do I create a Presigned URL to download a file from an S3 Bucket using Boto3? 如何使用 AWS SDK 为 Go 创建预签名的 POST URL - How to create a pre-signed POST URL using AWS SDK for Go 如何使用 Google Ko 构建和推送 Go 映像?你能告诉我 cloudbuild.yaml 创建映像并使用 Google 推送 go 映像的步骤吗? - How to build and push Go image using Google Ko?Could you tell me the steps for cloudbuild.yaml to create the image and push go image using Google ko? 如何使用 api 密钥或用户名密码访问 GMail API? - How to access GMail APIs using api key or username password? 如何在 DataGrip 中使用我的 gmail 帐户连接到 BigQuery 实例? - How to connect to a BigQuery instance using my gmail account in DataGrip? 使用 AWS-SES 时如何创建电子邮件线程? - How do I create an email thread when using AWS-SES? 如何使用 REST API 从服务帐户凭据创建访问令牌? - How do I create an Access Token from Service Account Credentials using REST API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM