I have a package mystuff
which deals with sending an email.
package mystuff
import (
"crypto/tls"
"gopkg.in/gomail.v2"
)
type Params struct {
From, To, Subject, Body, Filename string
}
func Mail(p Params) (err error) {
m := gomail.NewMessage()
m.SetHeader("From", p.From)
m.SetHeader("To", p.To)
m.SetHeader("Subject", p.Subject)
m.SetBody("text/plain", p.Body)
m.Attach(p.Filename)
d := gomail.Dialer{Host: "smtp.example.com", Port: 25}
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
if err := d.DialAndSend(m); err != nil {
panic(err)
}
return
}
and the main paskage which sends the email
package main
import . "mystuff"
func main() {
Mail(Params{From: "example@example.com", To: "some@gmail.com", Subject: "Sub", Body: "B", Filename: "/tmp/image.jpg" })
}
I would like to make Filename
as an optional parameter.
for example
Mail(Params{From: "example@example.com", To: "some@gmail.com", Subject: "Sub", Body: "B" })
}
Thank you