diff --git a/emailer/interface.go b/emailer/interface.go index 5a486fc..269bc38 100644 --- a/emailer/interface.go +++ b/emailer/interface.go @@ -3,6 +3,7 @@ package emailer type Attachment struct { Name string Data []byte + MimeType string } type Emailer interface { diff --git a/emailer/sendgrid.go b/emailer/sendgrid.go index 864c953..463be3e 100644 --- a/emailer/sendgrid.go +++ b/emailer/sendgrid.go @@ -39,7 +39,7 @@ func (o *SendgridApiMail) Send(toName string, to string, subject string, content var att mail.Attachment encoded := base64.StdEncoding.EncodeToString(attachments[i].Data) att.SetContent(encoded) - att.SetType("text/plain") + att.SetType(attachments[i].MimeType) att.SetFilename(attachments[i].Name) att.SetDisposition("attachment") toAdd = append(toAdd, &att) diff --git a/emailer/smtp.go b/emailer/smtp.go index 2586924..c290d09 100644 --- a/emailer/smtp.go +++ b/emailer/smtp.go @@ -91,7 +91,7 @@ func (o *SmtpMail) Send(toName string, to string, subject string, content string SetBody(mail.TextHTML, content) for _, v := range attachments { - email.Attach(&mail.File{Name: v.Name, Data: v.Data}) + email.Attach(&mail.File{Name: v.Name, Data: v.Data, MimeType: v.MimeType}) } err = email.Send(smtpClient) diff --git a/handler/routes.go b/handler/routes.go index ede3654..c1fc6af 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -547,14 +547,14 @@ func EmailClient(db store.IStore, mailer emailer.Emailer, emailSubject, emailCon globalSettings, _ := db.GetGlobalSettings() config := util.BuildClientConfig(*clientData.Client, server, globalSettings) - cfgAtt := emailer.Attachment{Name: "wg0.conf", Data: []byte(config)} + cfgAtt := emailer.Attachment{Name: "wg0.conf", Data: []byte(config), MimeType: "text/conf"} var attachments []emailer.Attachment if clientData.Client.PrivateKey != "" { qrdata, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(clientData.QRCode, "data:image/png;base64,")) if err != nil { return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "decoding: " + err.Error()}) } - qrAtt := emailer.Attachment{Name: "wg.png", Data: qrdata} + qrAtt := emailer.Attachment{Name: "wg.png", Data: qrdata, MimeType: "image/png"} attachments = []emailer.Attachment{cfgAtt, qrAtt} } else { attachments = []emailer.Attachment{cfgAtt}