Merge pull request #3 from ccamel/fix/fix-writer-close
Fix potential closing issues
This commit is contained in:
commit
15d6735778
|
@ -91,6 +91,7 @@ func (m *SendMailRequest) Execute() error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed initiating smtp connection (%s)", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
smtpClient, err := smtp.NewClient(conn, smtpServerHost)
|
||||
if err != nil {
|
||||
|
@ -120,17 +121,13 @@ func (m *SendMailRequest) Execute() error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed issuing DATA command (%s)", err)
|
||||
}
|
||||
defer smtpWriter.Close()
|
||||
|
||||
_, err = smtpWriter.Write([]byte(msg))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed sending mail content (%s)", err)
|
||||
}
|
||||
|
||||
err = smtpWriter.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed close smtp client (%s)", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue