Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In actuality it would be `email.NewEmail()` -- the lack of namespace specificity is due to the code examples already being part of the package. The issue with a simple `New()` 'constructor' is that there is ambiguity as to what struct it's creating.


   package main
   
   import (
       "log"
       "net/smtp"
       "github.com/jordan-wright/email"
   )
   
   func main() {
       e := email.NewEmail()
       e.From = "Jordan Wright <test@gmail.com>"
       e.To = []string{"test@example.com"}
       e.Bcc = []string{"test_bcc@example.com"}
       e.Cc = []string{"test_cc@example.com"}
       e.Subject = "Awesome Subject"
       e.Text = "Text Body is, of course, supported!"
       e.HTML = "<h1>Fancy HTML is supported, too!</h1>"
       err := e.Send("smtp.gmail.com:587",
           smtp.PlainAuth("", "x@gmail.com", "pw", "smtp.gmail.com"))
       if err != nil {
           log.Fatal(err)
       }
   }


There are dozens of instances of New() in the standard library.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: