database - 如何使用这些包 "google.golang.org/appengine/mail"在 Go 中上传附件

标签 database google-app-engine go

下面是我尝试用附件发送的代码。

    msg := &mail.Message{
                    Sender: "kasireddy002@gmail.com",
                    To:     []string{addr},
          Attachments : []Attachment{
                           Name :"file name",
                            Data :[]byte,
                        ContentID :"fileid",
                      },

                    Subject: "Welcome to Simplyst Health: Verify your account",
    if err := mail.Send(context, msg); err != nil {
                    log.Errorf(ctx, "Alas, my user, the email failed to sendeth: err)
                }

当我试图保存我的代码时,它抛出了一个错误。

错误:

cannot use []Attachment literal (type []Attachment) as type []"google.golang.org/appengine/mail".Attachment in field value

最佳答案

你只需要把它改成

msg := &mail.Message{
    Sender: "kasireddy002@gmail.com",
    To:     []string{addr},
    Attachments: []mail.Attachment{
        {
            Name:      "file name",
            Data:      []byte{},
            ContentID: "fileid",
        },
    },
    Subject: "Welcome to Simplyst Health: Verify your account",
}

只是指出您的代码存在的问题:

  • 在您的 mail.Message
  • 定义中存在错误检查
  • 附件 类型缺少包名称,邮件
  • 当您创建一部分附件而不仅仅是一个附件时,您需要在要添加的附件周围添加额外的{}

关于database - 如何使用这些包 "google.golang.org/appengine/mail"在 Go 中上传附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51765953/

相关文章:

MySql如何返回包含所有选定功能的所有项目

google-app-engine - 谷歌云 IAP,使用不记名 token 的身份验证给出错误代码 13 并且从未到达应用引擎实例

google-app-engine - 如何使 vendor 与 Google App Engine 一起工作?

ssh - 将公钥编码为 OpenSSH 格式以供显示

python - 获取 APSW 中的所有内容

java - 使用多个并发进程清空数据库表

mysql - 跨多个表搜索

google-app-engine - 如何在 Go 中的 AppEngine 数据存储区中建立多对多关系模型?

unit-testing - 如何对 Go Gin 处理程序函数进行单元测试?

google-app-engine - 如何使用 gcloud 将具有依赖关系的 golang 应用程序部署到应用程序引擎?