-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding low level SendMail function to Client.
- Loading branch information
1 parent
62f6b38
commit ee233dd
Showing
2 changed files
with
76 additions
and
22 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 |
---|---|---|
|
@@ -45,7 +45,40 @@ func main() { | |
} | ||
``` | ||
|
||
If you need more control, you can use `Client` instead. | ||
If you need more control, you can use `Client` instead. For example, if you | ||
want to send an email via a server without TLS or auth support, you can do | ||
something like this: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
|
||
"github.com/emersion/go-smtp" | ||
) | ||
|
||
func main() { | ||
// Setup connection to mail server, return Client instance | ||
c, err := smtp.Dial("mail.example.com:25") | ||
if err != nil { | ||
return err | ||
} | ||
defer c.Close() | ||
|
||
// Set the sender and recipient, and send the email all in one step. | ||
to := []string{"[email protected]"} | ||
msg := strings.NewReader("To: [email protected]\r\n" + | ||
"Subject: discount Gophers!\r\n" + | ||
"\r\n" + | ||
"This is the email body.\r\n") | ||
err := c.SendMail("[email protected]", to, msg) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
``` | ||
|
||
### Server | ||
|
||
|
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