使用gomail.v2创建新的* Dialer

I'm using gomail.v2 to send emails, and my code works fine. After composing a message msg I can just run

import ("gopkg.in/gomail.v2")

  ...
  d := gomail.NewDialer("smtp.example.com", 25, "username", "password")
  return d.DialAndSend(msg)
}

Of course I'd like to generalize this past a particular username and password and separate it into its own function, so I stubbed it out:

import ("gopkg.in/gomail.v2")

  ...
  d := MyDialer()
  return d.DialAndSend(msg)
}

func MyDialer() *Dialer {
  return gomail.NewDialer("smtp.example.com", 25, "username", "password")
}

But go croaks, complaining that it doesn't know about Dialer.

.\email.go:42: undefined: Dialer

Why is this? I'm using the same return type as NewDialer, which doesn't cause any problems.

func NewDialer(host string, port int, username, password string) *Dialer

What am I missing? I ran

go get -u gopkg.in/gomail.v2

to make sure I wasn't somehow running an out of date version of the package, but no luck there.

*Dialer and *gomail.Dialer are 2 different types. The specific error is because you don't have a Dialer type defined in your package, but you need to match the types in the signature, not just the name. Since gomail.NewDialer returns a *gomail.Dialer, use:

func MyDialer() *gomail.Dialer {