Skip to content

Commit

Permalink
Adding SetMimeType(typ mime.Type) method to Message interface. Depe…
Browse files Browse the repository at this point in the history
…ndencies update.
  • Loading branch information
Maya Sergeeva committed Jun 23, 2022
1 parent 19e4750 commit 6bd7c7e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions contracts/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (mm *Message) SetSubject(sbj string) error {
return nil
}

func (mm *Message) SetMimeType(typ mime.Type) {
mm.MimeType = typ
}

func (mm *Message) SetHTML(msg []byte) error {
if msg == nil {
mm.emptyContent()
Expand Down
1 change: 1 addition & 0 deletions contracts/messageInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type MessageInterface interface {
SetBccs(addrs mailing.MailAddressListInterface)
SetReplyTo(addr mailing.MailAddressInterface) error
SetSubject(sbj string) error
SetMimeType(typ mime.Type)
SetHTML(msg []byte) error
SetPlainText(msg []byte) error
AddAttachment(file MessageAttachmentInterface) error
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/mailgun/mailgun-go/v4 v4.6.2
github.com/mattbaird/gochimp v0.0.0-20200820164431-f1082bcdf63f
github.com/sendgrid/sendgrid-go v3.11.1+incompatible
github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha2
github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha3
github.com/stretchr/testify v1.7.1
github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208
github.com/xhit/go-simple-mail/v2 v2.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/sendgrid/rest v2.6.9+incompatible h1:1EyIcsNdn9KIisLW50MKwmSRSK+ekuei
github.com/sendgrid/rest v2.6.9+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE=
github.com/sendgrid/sendgrid-go v3.11.1+incompatible h1:ai0+woZ3r/+tKLQExznak5XerOFoD6S7ePO0lMV8WXo=
github.com/sendgrid/sendgrid-go v3.11.1+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha2 h1:WT5CvXlGEJ69lIPsBm/anuwoCnEajRwL0ha2aoLCaQM=
github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha2/go.mod h1:/qyni0G7nIAu2Hdp7VW3p+RwjhwvIKJtKdbbN2osywE=
github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha3 h1:KS2lDwGko4ATBvRCq0PSnLcxZvbottU3huqg+hRKm7A=
github.com/spacetab-io/configuration-structs-go/v2 v2.0.0-alpha3/go.mod h1:/qyni0G7nIAu2Hdp7VW3p+RwjhwvIKJtKdbbN2osywE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
Expand Down
7 changes: 6 additions & 1 deletion mailing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"

"github.com/spacetab-io/configuration-structs-go/v2/errors"
"github.com/spacetab-io/configuration-structs-go/v2/mailing"
"github.com/spacetab-io/mails-go/contracts"
"github.com/spacetab-io/mails-go/providers"
Expand Down Expand Up @@ -49,7 +50,7 @@ func NewMailing(providerCfg mailing.MailProviderConfigInterface, msgCfg mailing.
case mailing.MailProviderSMTP:
provider, err = providers.NewSMTP(providerCfg)
default:
return Mailing{}, mailing.ErrUnknownProvider
return Mailing{}, errors.ErrUnknownProvider
}

if err != nil {
Expand All @@ -64,6 +65,10 @@ func NewMailingForProvider(provider contracts.ProviderInterface, msgCfg mailing.
}

func (m Mailing) Send(ctx context.Context, msg contracts.MessageInterface) error {
if msg.GetMimeType().IsEmpty() && !m.msgCfg.GetMimeType().IsEmpty() {
msg.SetMimeType(m.msgCfg.GetMimeType())
}

if msg.GetFrom().IsEmpty() && !m.msgCfg.GetFrom().IsEmpty() {
_ = msg.SetFrom(m.msgCfg.GetFrom())
}
Expand Down

0 comments on commit 6bd7c7e

Please sign in to comment.