-
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.
added support to send smtp mail with go-mail (#21)
- Loading branch information
1 parent
e729a4e
commit 02e8a08
Showing
4 changed files
with
43 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package smtp | ||
|
||
import ( | ||
mail "github.com/go-mail/gomail" | ||
"github.com/irdaislakhuafa/go-sdk/codes" | ||
"github.com/irdaislakhuafa/go-sdk/errors" | ||
) | ||
|
||
type GoMailInterface interface { | ||
DialAndSend(messages ...*mail.Message) error | ||
} | ||
|
||
type gomailImpl struct { | ||
dialer *mail.Dialer | ||
} | ||
|
||
func InitGoMail(cfg Config) GoMailInterface { | ||
result := &gomailImpl{ | ||
dialer: mail.NewDialer(cfg.Host, int(cfg.Port), cfg.Username, cfg.Password), | ||
} | ||
return result | ||
} | ||
|
||
func (g *gomailImpl) DialAndSend(messages ...*mail.Message) error { | ||
if err := g.dialer.DialAndSend(messages...); err != nil { | ||
return errors.NewWithCode(codes.CodeSMTP, "failed to send messages, %v", err) | ||
} | ||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package smtp | ||
|
||
type Config struct { | ||
Username string | ||
Password string | ||
Host string | ||
Port int64 | ||
} |