-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from linyows/bugfix
Bugfix
- Loading branch information
Showing
4 changed files
with
28 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/linyows/warp | ||
|
||
go 1.17 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/DATA-DOG/go-sqlmock v1.5.0 | ||
|
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 |
---|---|---|
|
@@ -42,24 +42,38 @@ type SMTPClient struct { | |
} | ||
|
||
func (c *SMTPClient) SendEmail() error { | ||
from := "[email protected]" | ||
to := "[email protected]" | ||
|
||
s, err := smtp.Dial(fmt.Sprintf("%s:%d", c.IP, c.Port)) | ||
if err != nil { | ||
return fmt.Errorf("smtp.Dial(%s:%d): %#v", c.IP, c.Port, err) | ||
} | ||
if err := s.Mail("[email protected]"); err != nil { | ||
if ok, _ := s.Extension("STARTTLS"); ok { | ||
return fmt.Errorf("STARTTLS is available: %#v", s) | ||
} | ||
if err := s.Mail(from); err != nil { | ||
return fmt.Errorf("smtp mail error: %#v", err) | ||
} | ||
if err := s.Rcpt("[email protected]"); err != nil { | ||
if err := s.Rcpt(to); err != nil { | ||
return fmt.Errorf("smtp rcpt error: %#v", err) | ||
} | ||
wc, err := s.Data() | ||
if err != nil { | ||
return fmt.Errorf("smtp data error: %#v", err) | ||
} | ||
_, err = fmt.Fprintf(wc, "This is the email body") | ||
|
||
prefix := []byte(fmt.Sprintf("To: %s\nFrom: %s\nSubject: Test\n\n", to, from)) | ||
data := make([]byte, 1024) | ||
for i := 0; i < len(data); i += 4 { | ||
copy(data[i:i+4], []byte("Test")) | ||
} | ||
data = append(prefix, data...) | ||
_, err = wc.Write(data) | ||
if err != nil { | ||
return fmt.Errorf("smtp data print error: %#v", err) | ||
} | ||
|
||
if err = wc.Close(); err != nil { | ||
return fmt.Errorf("smtp close print error: %#v", err) | ||
} | ||
|