-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move sendgrid config outside of mailer package (#7)
move sendgrid config outside of mailer package and use params instead of struct for instatiation
- Loading branch information
1 parent
455a404
commit a59fb2d
Showing
3 changed files
with
56 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,32 +10,39 @@ import ( | |
"github.com/mailgun/mailgun-go/v4" | ||
) | ||
|
||
// MailgunConfig has the parameters to use the Mailgun service | ||
type MailgunConfig struct { | ||
Domain string | ||
Key string | ||
UseEUServer bool | ||
} | ||
|
||
// MailgunMailer implements the Mailer interface to send emails using Mailgun service | ||
type MailgunMailer struct { | ||
client *mailgun.MailgunImpl | ||
|
||
senderEmail string | ||
senderName string | ||
} | ||
|
||
// NewMailgunMailer creates a new Mailer to send emails through Mailgun | ||
func NewMailgunMailer(conf MailgunConfig) (*MailgunMailer, error) { | ||
if len(conf.Key) == 0 { | ||
func NewMailgunMailer(domain string, key string, senderEmail string, | ||
senderName string, useEUServer bool) (*MailgunMailer, error) { | ||
|
||
if len(domain) == 0 { | ||
return nil, fmt.Errorf("missing Mailgun Domain") | ||
} | ||
if len(key) == 0 { | ||
return nil, fmt.Errorf("missing Mailgun Key") | ||
} | ||
if len(conf.Domain) == 0 { | ||
return nil, fmt.Errorf("missing Mailgun Domain") | ||
if len(senderEmail) == 0 { | ||
return nil, fmt.Errorf("missing Mailgun Sender Email Address") | ||
} | ||
client := mailgun.NewMailgun(conf.Domain, conf.Key) | ||
if conf.UseEUServer { | ||
if len(senderName) == 0 { | ||
senderName = senderEmail | ||
} | ||
|
||
client := mailgun.NewMailgun(domain, key) | ||
if useEUServer { | ||
client.SetAPIBase(mailgun.APIBaseEU) | ||
} | ||
return &MailgunMailer{ | ||
client: client, | ||
client: client, | ||
senderEmail: senderEmail, | ||
senderName: senderName, | ||
}, nil | ||
} | ||
|
||
|
@@ -57,5 +64,5 @@ func (m *MailgunMailer) Send(e Email) error { | |
|
||
// Sender returns the default sender address and name | ||
func (m *MailgunMailer) Sender() (string, string) { | ||
return "[email protected]", "No Reply" | ||
return m.senderEmail, m.senderName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters