This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move gomail into interal because of go-mail/mail#39
- Loading branch information
Showing
18 changed files
with
1,493 additions
and
3 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,17 @@ | ||
|
||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
|
||
# IDE's | ||
.idea/ |
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,25 @@ | ||
language: go | ||
|
||
go: | ||
- 1.2 | ||
- 1.3 | ||
- 1.4 | ||
- 1.5 | ||
- 1.6 | ||
- 1.7 | ||
- 1.8 | ||
- 1.9 | ||
- master | ||
|
||
# safelist | ||
branches: | ||
only: | ||
- master | ||
- v2 | ||
|
||
notifications: | ||
email: false | ||
|
||
before_install: | ||
- mkdir -p $GOPATH/src/gopkg.in && | ||
ln -s ../github.com/go-mail/mail $GOPATH/src/gopkg.in/mail.v2 |
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,83 @@ | ||
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## *Unreleased* | ||
|
||
## [2.3.0] - 2018-11-10 | ||
|
||
### Added | ||
|
||
- #12: Adds `SendError` to provide additional info about the cause and index of | ||
a failed attempt to transmit a batch of messages. | ||
- go-gomail#78: Adds new `Message` methods for attaching and embedding | ||
`io.Reader`s: `AttachReader` and `EmbedReader`. | ||
- #39: Adds support for Go modules (Go 1.11+). | ||
|
||
### Fixed | ||
|
||
- #26: Fixes RFC 1341 compliance by properly capitalizing the | ||
`MIME-Version` header. | ||
- #30: Fixes IO errors being silently dropped in `Message.WriteTo`. | ||
|
||
## [2.2.0] - 2018-03-01 | ||
|
||
### Added | ||
|
||
- #20: Adds `Message.SetBoundary` to allow specifying a custom MIME boundary. | ||
- #22: Adds `Message.SetBodyWriter` to make it easy to use text/template and | ||
html/template for message bodies. Contributed by Quantcast. | ||
- #25: Adds `Dialer.StartTLSPolicy` so that `MandatoryStartTLS` can be required, | ||
or `NoStartTLS` can disable it. Contributed by Quantcast. | ||
|
||
## [2.1.0] - 2017-12-14 | ||
|
||
### Added | ||
|
||
- go-gomail#40: Adds `Dialer.LocalName` field to allow specifying the hostname | ||
sent with SMTP's HELO command. | ||
- go-gomail#47: `Message.SetBody`, `Message.AddAlternative`, and | ||
`Message.AddAlternativeWriter` allow specifying the encoding of message parts. | ||
- `Dialer.Dial`'s returned `SendCloser` automatically redials after a timeout. | ||
- go-gomail#55, go-gomail#56: Adds `Rename` to allow specifying filename | ||
of an attachment. | ||
- go-gomail#100: Exports `NetDialTimeout` to allow setting a custom dialer. | ||
- go-gomail#70: Adds `Dialer.Timeout` field to allow specifying a timeout for | ||
dials, reads, and writes. | ||
|
||
### Changed | ||
|
||
- go-gomail#52: `Dialer.Dial` automatically uses CRAM-MD5 when available. | ||
- `Dialer.Dial` specifies a default timeout of 10 seconds. | ||
- Gomail is forked from <https://github.com/go-gomail/gomail/> to | ||
<https://github.com/go-mail/mail/>. | ||
|
||
### Deprecated | ||
|
||
- go-gomail#52: `NewPlainDialer` is deprecated in favor of `NewDialer`. | ||
|
||
### Fixed | ||
|
||
- go-gomail#41, go-gomail#42: Fixes a panic when a `Message` contains a | ||
nil header. | ||
- go-gomail#44: Fixes `AddAlternativeWriter` replacing the message body instead | ||
of adding a body part. | ||
- go-gomail#53: Folds long header lines for RFC 2047 compliance. | ||
- go-gomail#54: Fixes `Message.FormatAddress` when name is blank. | ||
|
||
## [2.0.0] - 2015-09-02 | ||
|
||
- Mailer has been removed. It has been replaced by Dialer and Sender. | ||
- `File` type and the `CreateFile` and `OpenFile` functions have been removed. | ||
- `Message.Attach` and `Message.Embed` have a new signature. | ||
- `Message.GetBodyWriter` has been removed. Use `Message.AddAlternativeWriter` | ||
instead. | ||
- `Message.Export` has been removed. `Message.WriteTo` can be used instead. | ||
- `Message.DelHeader` has been removed. | ||
- The `Bcc` header field is no longer sent. It is far more simpler and | ||
efficient: the same message is sent to all recipients instead of sending a | ||
different email to each Bcc address. | ||
- LoginAuth has been removed. `NewPlainDialer` now implements the LOGIN | ||
authentication mechanism when needed. | ||
- Go 1.2 is now required instead of Go 1.3. No external dependency are used when | ||
using Go 1.5. |
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,20 @@ | ||
Thank you for contributing to Gomail! Here are a few guidelines: | ||
|
||
## Bugs | ||
|
||
If you think you found a bug, create an issue and supply the minimum amount | ||
of code triggering the bug so it can be reproduced. | ||
|
||
|
||
## Fixing a bug | ||
|
||
If you want to fix a bug, you can send a pull request. It should contains a | ||
new test or update an existing one to cover that bug. | ||
|
||
|
||
## New feature proposal | ||
|
||
If you think Gomail lacks a feature, you can open an issue or send a pull | ||
request. I want to keep Gomail code and API as simple as possible so please | ||
describe your needs so we can discuss whether this feature should be added to | ||
Gomail or not. |
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,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Alexandre Cesaro | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,129 @@ | ||
# Gomail | ||
[](https://travis-ci.org/go-mail/mail) [](http://gocover.io/github.com/go-mail/mail) [](https://godoc.org/github.com/go-mail/mail) | ||
|
||
This is an actively maintained fork of [Gomail][1] and includes fixes and | ||
improvements for a number of outstanding issues. The current progress is | ||
as follows: | ||
|
||
- [x] Timeouts and retries can be specified outside of the 10 second default. | ||
- [x] Proxying is supported through specifying a custom [NetDialTimeout][2]. | ||
- [ ] Filenames are properly encoded for non-ASCII characters. | ||
- [ ] Email addresses are properly encoded for non-ASCII characters. | ||
- [ ] Embedded files and attachments are tested for their existence. | ||
- [ ] An `io.Reader` can be supplied when embedding and attaching files. | ||
|
||
See [Transitioning Existing Codebases][3] for more information on switching. | ||
|
||
[1]: https://github.com/go-gomail/gomail | ||
[2]: https://godoc.org/gopkg.in/mail.v2#NetDialTimeout | ||
[3]: #transitioning-existing-codebases | ||
|
||
## Introduction | ||
|
||
Gomail is a simple and efficient package to send emails. It is well tested and | ||
documented. | ||
|
||
Gomail can only send emails using an SMTP server. But the API is flexible and it | ||
is easy to implement other methods for sending emails using a local Postfix, an | ||
API, etc. | ||
|
||
It requires Go 1.2 or newer. With Go 1.5, no external dependencies are used. | ||
|
||
|
||
## Features | ||
|
||
Gomail supports: | ||
- Attachments | ||
- Embedded images | ||
- HTML and text templates | ||
- Automatic encoding of special characters | ||
- SSL and TLS | ||
- Sending multiple emails with the same SMTP connection | ||
|
||
|
||
## Documentation | ||
|
||
https://godoc.org/github.com/go-mail/mail | ||
|
||
|
||
## Download | ||
|
||
If you're already using a dependency manager, like [dep][dep], use the following | ||
import path: | ||
|
||
``` | ||
github.com/go-mail/mail | ||
``` | ||
|
||
If you *aren't* using vendoring, `go get` the [Gopkg.in](http://gopkg.in) | ||
import path: | ||
|
||
``` | ||
gopkg.in/mail.v2 | ||
``` | ||
|
||
[dep]: https://github.com/golang/dep#readme | ||
|
||
## Examples | ||
|
||
See the [examples in the documentation](https://godoc.org/github.com/go-mail/mail#example-package). | ||
|
||
|
||
## FAQ | ||
|
||
### x509: certificate signed by unknown authority | ||
|
||
If you get this error it means the certificate used by the SMTP server is not | ||
considered valid by the client running Gomail. As a quick workaround you can | ||
bypass the verification of the server's certificate chain and host name by using | ||
`SetTLSConfig`: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
|
||
"gopkg.in/mail.v2" | ||
) | ||
|
||
func main() { | ||
d := mail.NewDialer("smtp.example.com", 587, "user", "123456") | ||
d.TLSConfig = &tls.Config{InsecureSkipVerify: true} | ||
|
||
// Send emails using d. | ||
} | ||
``` | ||
|
||
Note, however, that this is insecure and should not be used in production. | ||
|
||
### Transitioning Existing Codebases | ||
|
||
If you're already using the original Gomail, switching is as easy as updating | ||
the import line to: | ||
|
||
``` | ||
import gomail "gopkg.in/mail.v2" | ||
``` | ||
|
||
## Contribute | ||
|
||
Contributions are more than welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for | ||
more info. | ||
|
||
|
||
## Change log | ||
|
||
See [CHANGELOG.md](CHANGELOG.md). | ||
|
||
|
||
## License | ||
|
||
[MIT](LICENSE) | ||
|
||
|
||
## Support & Contact | ||
|
||
You can ask questions on the [Gomail | ||
thread](https://groups.google.com/d/topic/golang-nuts/jMxZHzvvEVg/discussion) | ||
in the Go mailing-list. |
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,49 @@ | ||
package mail | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"net/smtp" | ||
) | ||
|
||
// loginAuth is an smtp.Auth that implements the LOGIN authentication mechanism. | ||
type loginAuth struct { | ||
username string | ||
password string | ||
host string | ||
} | ||
|
||
func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) { | ||
if !server.TLS { | ||
advertised := false | ||
for _, mechanism := range server.Auth { | ||
if mechanism == "LOGIN" { | ||
advertised = true | ||
break | ||
} | ||
} | ||
if !advertised { | ||
return "", nil, errors.New("gomail: unencrypted connection") | ||
} | ||
} | ||
if server.Name != a.host { | ||
return "", nil, errors.New("gomail: wrong host name") | ||
} | ||
return "LOGIN", nil, nil | ||
} | ||
|
||
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) { | ||
if !more { | ||
return nil, nil | ||
} | ||
|
||
switch { | ||
case bytes.Equal(fromServer, []byte("Username:")): | ||
return []byte(a.username), nil | ||
case bytes.Equal(fromServer, []byte("Password:")): | ||
return []byte(a.password), nil | ||
default: | ||
return nil, fmt.Errorf("gomail: unexpected server challenge: %s", fromServer) | ||
} | ||
} |
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,6 @@ | ||
// Package gomail provides a simple interface to compose emails and to mail them | ||
// efficiently. | ||
// | ||
// More info on Github: https://github.com/go-mail/mail | ||
// | ||
package mail |
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,16 @@ | ||
package mail | ||
|
||
import "fmt" | ||
|
||
// A SendError represents the failure to transmit a Message, detailing the cause | ||
// of the failure and index of the Message within a batch. | ||
type SendError struct { | ||
// Index specifies the index of the Message within a batch. | ||
Index uint | ||
Cause error | ||
} | ||
|
||
func (err *SendError) Error() string { | ||
return fmt.Sprintf("gomail: could not send email %d: %v", | ||
err.Index+1, err.Cause) | ||
} |
Oops, something went wrong.