Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

Fixing Attachment Error New Fork #14

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .gitignore

This file was deleted.

12 changes: 0 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ go:
- 1.4
- 1.5
- 1.6
- 1.7
- 1.8
- 1.9
- tip

# safelist
branches:
only:
- master
- v2

notifications:
email: false
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## 2017-12-06 Original project forked
https://github.com/go-gomail/gomail/issues/104

## [2.0.0] - 2015-09-02

- Mailer has been removed. It has been replaced by Dialer and Sender.
Expand Down
60 changes: 18 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
# Gomail
[![Build Status](https://travis-ci.org/go-mail/mail.svg?branch=master)](https://travis-ci.org/go-mail/mail) [![Code Coverage](http://gocover.io/_badge/github.com/go-mail/mail)](http://gocover.io/github.com/go-mail/mail) [![Documentation](https://godoc.org/github.com/go-mail/mail?status.svg)](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
[![Build Status](https://travis-ci.org/go-gomail/gomail.svg?branch=v2)](https://travis-ci.org/go-gomail/gomail) [![Code Coverage](http://gocover.io/_badge/gopkg.in/gomail.v2)](http://gocover.io/gopkg.in/gomail.v2) [![Documentation](https://godoc.org/gopkg.in/gomail.v2?status.svg)](https://godoc.org/gopkg.in/gomail.v2)

## Introduction

Expand All @@ -27,6 +10,9 @@ 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 is versioned using [gopkg.in](https://gopkg.in) so I promise
there will never be backward incompatible changes within each version.

It requires Go 1.2 or newer. With Go 1.5, no external dependencies are used.


Expand All @@ -43,17 +29,17 @@ Gomail supports:

## Documentation

https://godoc.org/github.com/go-mail/mail
https://godoc.org/gopkg.in/gomail.v2


## Download

go get gopkg.in/mail.v2
go get gopkg.in/gomail.v2


## Examples

See the [examples in the documentation](https://godoc.org/github.com/go-mail/mail#example-package).
See the [examples in the documentation](https://godoc.org/gopkg.in/gomail.v2#example-package).


## FAQ
Expand All @@ -65,33 +51,23 @@ 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
package main

import (
"crypto/tls"
import (
"crypto/tls"

"gopkg.in/mail.v2"
)
"gopkg.in/gomail.v2"
)

func main() {
d := mail.NewDialer("smtp.example.com", 587, "user", "123456")
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
func main() {
d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}

// Send emails using d.
}
```
// 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

Expand All @@ -109,7 +85,7 @@ See [CHANGELOG.md](CHANGELOG.md).
[MIT](LICENSE)


## Support & Contact
## Contact

You can ask questions on the [Gomail
thread](https://groups.google.com/d/topic/golang-nuts/jMxZHzvvEVg/discussion)
Expand Down
2 changes: 1 addition & 1 deletion auth.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mail
package gomail

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion auth_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mail
package gomail

import (
"net/smtp"
Expand Down
5 changes: 2 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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
// More info on Github: https://github.com/go-gomail/gomail
package gomail
46 changes: 23 additions & 23 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mail_test
package gomail_test

import (
"fmt"
Expand All @@ -7,19 +7,19 @@ import (
"log"
"time"

"gopkg.in/mail.v2"
"gopkg.in/gomail.v2"
)

func Example() {
m := mail.NewMessage()
m := gomail.NewMessage()
m.SetHeader("From", "alex@example.com")
m.SetHeader("To", "bob@example.com", "cora@example.com")
m.SetAddressHeader("Cc", "dan@example.com", "Dan")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
m.Attach("/home/Alex/lolcat.jpg")

d := mail.NewDialer("smtp.example.com", 587, "user", "123456")
d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")

// Send the email to Bob, Cora and Dan.
if err := d.DialAndSend(m); err != nil {
Expand All @@ -29,12 +29,12 @@ func Example() {

// A daemon that listens to a channel and sends all incoming messages.
func Example_daemon() {
ch := make(chan *mail.Message)
ch := make(chan *gomail.Message)

go func() {
d := mail.NewDialer("smtp.example.com", 587, "user", "123456")
d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")

var s mail.SendCloser
var s gomail.SendCloser
var err error
open := false
for {
Expand All @@ -49,7 +49,7 @@ func Example_daemon() {
}
open = true
}
if err := mail.Send(s, m); err != nil {
if err := gomail.Send(s, m); err != nil {
log.Print(err)
}
// Close the connection to the SMTP server if no email was sent in
Expand Down Expand Up @@ -79,20 +79,20 @@ func Example_newsletter() {
Address string
}

d := mail.NewDialer("smtp.example.com", 587, "user", "123456")
d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")
s, err := d.Dial()
if err != nil {
panic(err)
}

m := mail.NewMessage()
m := gomail.NewMessage()
for _, r := range list {
m.SetHeader("From", "no-reply@example.com")
m.SetAddressHeader("To", r.Address, r.Name)
m.SetHeader("Subject", "Newsletter #1")
m.SetBody("text/html", fmt.Sprintf("Hello %s!", r.Name))

if err := mail.Send(s, m); err != nil {
if err := gomail.Send(s, m); err != nil {
log.Printf("Could not send email to %q: %v", r.Address, err)
}
m.Reset()
Expand All @@ -101,58 +101,58 @@ func Example_newsletter() {

// Send an email using a local SMTP server.
func Example_noAuth() {
m := mail.NewMessage()
m := gomail.NewMessage()
m.SetHeader("From", "from@example.com")
m.SetHeader("To", "to@example.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/plain", "Hello!")

d := mail.Dialer{Host: "localhost", Port: 587}
d := gomail.Dialer{Host: "localhost", Port: 587}
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}

// Send an email using an API or postfix.
func Example_noSMTP() {
m := mail.NewMessage()
m := gomail.NewMessage()
m.SetHeader("From", "from@example.com")
m.SetHeader("To", "to@example.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/plain", "Hello!")

s := mail.SendFunc(func(from string, to []string, msg io.WriterTo) error {
s := gomail.SendFunc(func(from string, to []string, msg io.WriterTo) error {
// Implements you email-sending function, for example by calling
// an API, or running postfix, etc.
fmt.Println("From:", from)
fmt.Println("To:", to)
return nil
})

if err := mail.Send(s, m); err != nil {
if err := gomail.Send(s, m); err != nil {
panic(err)
}
// Output:
// From: from@example.com
// To: [to@example.com]
}

var m *mail.Message
var m *gomail.Message

func ExampleSetCopyFunc() {
m.Attach("foo.txt", mail.SetCopyFunc(func(w io.Writer) error {
m.Attach("foo.txt", gomail.SetCopyFunc(func(w io.Writer) error {
_, err := w.Write([]byte("Content of foo.txt"))
return err
}))
}

func ExampleSetHeader() {
h := map[string][]string{"Content-ID": {"<foo@bar.mail>"}}
m.Attach("foo.jpg", mail.SetHeader(h))
m.Attach("foo.jpg", gomail.SetHeader(h))
}

func ExampleRename() {
m.Attach("/tmp/0000146.jpg", mail.Rename("picture.jpg"))
m.Attach("/tmp/0000146.jpg", gomail.Rename("picture.jpg"))
}

func ExampleMessage_AddAlternative() {
Expand Down Expand Up @@ -211,13 +211,13 @@ func ExampleMessage_SetHeaders() {
}

func ExampleSetCharset() {
m = mail.NewMessage(mail.SetCharset("ISO-8859-1"))
m = gomail.NewMessage(gomail.SetCharset("ISO-8859-1"))
}

func ExampleSetEncoding() {
m = mail.NewMessage(mail.SetEncoding(mail.Base64))
m = gomail.NewMessage(gomail.SetEncoding(gomail.Base64))
}

func ExampleSetPartEncoding() {
m.SetBody("text/plain", "Hello!", mail.SetPartEncoding(mail.Unencoded))
m.SetBody("text/plain", "Hello!", gomail.SetPartEncoding(gomail.Unencoded))
}
4 changes: 3 additions & 1 deletion message.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mail
package gomail

import (
"bytes"
Expand Down Expand Up @@ -240,6 +240,7 @@ func SetPartEncoding(e Encoding) PartSetting {

type file struct {
Name string
originalName string
Header map[string][]string
CopyFunc func(w io.Writer) error
}
Expand Down Expand Up @@ -285,6 +286,7 @@ func SetCopyFunc(f func(io.Writer) error) FileSetting {

func (m *Message) appendFile(list []*file, name string, settings []FileSetting) []*file {
f := &file{
originalName: filepath.Base(name),
Name: filepath.Base(name),
Header: make(map[string][]string),
CopyFunc: func(w io.Writer) error {
Expand Down
Loading