如何使用 Golang 将 MP4 填充附加到邮件(我使用的是 Gomail)



这是代码:

func sendMail() error{
m := gomail.NewMessage()
m.SetHeader("From", From)
m.SetHeader("To", "bacobas.f@gmail.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
m.Attach("./video.mp4")
//m.Attach("./Autorizzazione.pdf")
d := gomail.NewDialer(SmtpHost, SmtpPort, From, PswFrom)
// Send the email to Bob, Cora and Dan.
if err := d.DialAndSend(m); err != nil {
return err
}
return nil}

如果附加";Autorizzazione.pdf";它是有效的。如果我不附上蚂蚁。但如果我尝试附加这个.mp4文件,输出是Error: gomail: could not send email 1: write tcp <my LAN wi-fi ip address>:54988->142.250.147.109:587: wsasend: An existing connection was forcibly closed by the remote host.

这个函数是在我的小http服务器中的CCD_ 2内部调用的"印刷的"作为该api 的返回

有人能帮帮我吗?

以下示例适用于您吗?

来源:使用SMTP、Gmail和OAuth2 通过GO(Golang(发送电子邮件和附件

package gomail
import (
"errors"
"fmt"
"net/smtp"
)
var emailAuth smtp.Auth
func SendEmailSMTP(to []string, data interface{}, template string) (bool, error) {
emailHost := "smtp.gmail.com"
emailFrom := "yourEmail@gmail.com"
emailPassword := "yourEmailPassword"
emailPort := 587
emailAuth = smtp.PlainAuth("", emailFrom, emailPassword, emailHost)
emailBody, err := parseTemplate(template, data)
if err != nil {
return false, errors.New("unable to parse email template")
}
mime := "MIME-version: 1.0;nContent-Type: text/plain; charset="UTF-8";nn"
subject := "Subject: " + "Test Email" + "!n"
msg := []byte(subject + mime + "n" + emailBody)
addr := fmt.Sprintf("%s:%s", emailHost, emailPort)
if err := smtp.SendMail(addr, emailAuth, emailFrom, to, msg); err != nil {
return false, err
}
return true, nil
}

相关内容

  • 没有找到相关文章

最新更新