下面是我尝试用附件发送的代码。
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/