[ANN] Gomail v2: sending emails faster

4786 views
Skip to first unread message

Alexandre Cesaro

unread,
Sep 2, 2015, 7:55:26 AM9/2/15
to golang-nuts
Hi,

I just released the second version of Gomail.

There are quite a few backward-incompatible changes since Gomail v1 but it brings lots of good stuff:
  • A great focus was placed on performances. Gomail v2 is way more efficient than Gomail v1 to send a large number of emails (see the Daemon or Newsletter examples).
  • The API is now clearer and way more flexible.
  • The documentation improved and many examples were added.
  • All existing issues have been closed.
  • The minimum Go version is now 1.2 instead of 1.3. No external dependencies are used with Go 1.5.

Alexandre Cesaro

unread,
Sep 2, 2015, 4:02:32 PM9/2/15
to golang-nuts
Some people told me that Gmail decided to consider my message as phishing. But don't worry I am not stealing your passwords :)

stan.s...@gmail.com

unread,
Sep 24, 2015, 9:30:13 AM9/24/15
to golang-nuts
Hello Alexandre,
thanks for your great work.
I was wondering if you plan to include GPG features ? (sign emails for example)
If not, do you know a project I could look at ?

Thank again.
Regards,
Stan.

Alexandre Cesaro

unread,
Sep 24, 2015, 10:38:05 AM9/24/15
to golang-nuts, stan.s...@gmail.com
I haven't had the need to sign or encrypt emails so I haven't planned working on such features in the immediate future.
However it would be a great addition to Gomail and I might add them someday.

In the meantime you will need to use a package such as x/crypto/openpgp and implement RFC 3156 by yourself.

Feel free to open an issue on Github so that other users can chime in.

qicong...@gmail.com

unread,
Oct 11, 2015, 2:35:18 PM10/11/15
to golang-nuts
Hi Alexandre,

In gomail.v1 I can send emails by 

go mailer.Send(msg)

But in gomail.v2 I failed to send emails by 

go d.DialAndSend(msg)

Is it possible to send it via goroutine? I have a web application and cannot wait for so long.

Thanks!
Qicong

Alexandre Cesaro

unread,
Oct 11, 2015, 4:54:06 PM10/11/15
to qicong...@gmail.com, golang-nuts
Sure, it is still possible to send emails via a goroutine. Can you show more code?

Does it works when you do not use a goroutine?

And you should handle the error returned by DialAndSend:

go func() {
if err := d.DialAndSend(msg); err != nil {
log.Print(err)
}
}()

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/jMxZHzvvEVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Manlio Perillo

unread,
Oct 14, 2015, 12:30:34 PM10/14/15
to golang-nuts
Il giorno mercoledì 2 settembre 2015 13:55:26 UTC+2, Alexandre Cesaro ha scritto:
Hi,

I just released the second version of Gomail.


Thanks for the project.
I have just a question about the API.

Why do you have SetHeader and SetHeaders methods for the Message type, but only SetHeader function for FileSetting
(that behaves like SetHeaders method)?


> [...]

Regards  Manlio

Alexandre Cesaro

unread,
Oct 14, 2015, 12:40:13 PM10/14/15
to Manlio Perillo, golang-nuts
You are right. The API could be more coherent for these methods.

--

di...@gooddoglabs.com

unread,
Nov 13, 2015, 10:21:36 AM11/13/15
to golang-nuts
Hi Alexandre,
Firstly, great work.  Secondly, have you considered a scenario where SMTP Auth & SSL/TLS is not required.  I'm looking through source and can't find a way to deliver message without SMTP Auth and with SSL/TLS disabled.

Thanks,
Dino


On Wednesday, September 2, 2015 at 7:55:26 AM UTC-4, Alexandre Cesaro wrote:

Alexandre Cesaro

unread,
Nov 13, 2015, 10:36:41 AM11/13/15
to golang-nuts, di...@gooddoglabs.com
You can disable the STARTTLS extension on your SMTP server and use the no auth example: https://godoc.org/gopkg.in/gomail.v2#example-package--NoAuth

If you cannot disable the STARTTLS extension then I can add a DisableTLS field to the Dialer.

kindl...@gmail.com

unread,
Apr 7, 2016, 12:08:01 PM4/7/16
to golang-nuts, di...@gooddoglabs.com
The noauth example doesn't seem to work:

package main

import (
"gopkg.in/gomail.v2"
)




func main() {
m := gomail.NewMessage()
m.SetHeader("From", "fr...@example.com")
m.SetHeader("To", "t...@example.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/plain", "Hello!")

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



I got this error:


GOROOT=/usr/local/Cellar/go/1.6/libexec
GOPATH=/Users/kaiyin/golang
/usr/local/Cellar/go/1.6/libexec/bin/go run /Users/kaiyin/IdeaProjects/gomail/main.go
panic: 454 4.7.0 TLS not available due to local problem

goroutine 1 [running]:
panic(0x244ca0, 0xc820010b20)
	/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
main.main()
	/Users/kaiyin/IdeaProjects/gomail/main.go:19 +0x342
exit status 2

Alexandre Cesaro

unread,
Apr 8, 2016, 4:43:46 AM4/8/16
to kindl...@gmail.com, golang-nuts, di...@gooddoglabs.com
You should disable StartTLS on your server. If you cannot do that, please open an issue on Github: https://github.com/go-gomail/gomail/issues

--

simone.g...@gmail.com

unread,
Apr 10, 2016, 8:29:07 AM4/10/16
to golang-nuts, kindl...@gmail.com, di...@gooddoglabs.com
Hi Alexandro,
  greetings and thank you for Gomail v2.

I'm trying to send an email but I got this message:

panic: gomail: could not send email 1: mail: missing phrase

goroutine 1 [running]:
panic(0x647320, 0xc8203a6c70)
/home/demo/programs/go/src/runtime/panic.go:464 +0x3e6
main.main()
/home/demo/src/gomail.v2.example/gomail.v2.examp.go:23 +0x4f9

I'm using go 1.6 
I've tried both on windows and Linux: same error.
I copied the library example from the godoc and updated with my credentials; which are working with the base "net/smtp"

Any Clue?

Simone

PS windows output:

panic: gomail: could not send email 1: mail: missing phrase


goroutine 1 [running]:

panic(0x5ce460, 0x10c3f368)

C:/Go/src/runtime/panic.go:464 +0x326

main.main()

C:/Projects/src/go/gomail.v2.example/gomail.v2.examp.go:23 +0x3d7

Alexandre Cesaro

unread,
Apr 10, 2016, 8:36:58 AM4/10/16
to simone.g...@gmail.com, golang-nuts
Could you show your code?

--

simone.g...@gmail.com

unread,
Apr 11, 2016, 8:21:36 AM4/11/16
to golang-nuts, simone.g...@gmail.com
Sure! I changed the account and password for security reason.


    m := gomail.NewMessage()
    m.SetHeader("From", "Automation Autofast")
    m.SetHeader("To", "us...@gmail.com")
    m.SetHeader("Subject", "Very good library")
    m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
    m.Attach("p.jpg")

    d := gomail.NewDialer("smtp.gmail.com", 587, "us...@gmail.com", "secret")

    if err := d.DialAndSend(m); err != nil {
        panic(err)
    }


Alexandre Cesaro

unread,
Apr 11, 2016, 8:28:49 AM4/11/16
to Simone Giacomelli, golang-nuts
Your "From" address is invalid. It should be something like:

m.SetHeader("From", "va...@email.com")

or

m.SetAddressHeader("From", "va...@email.com", "Automation Autofast")

I will make the error message clearer.

simone.g...@gmail.com

unread,
Apr 12, 2016, 3:38:37 AM4/12/16
to golang-nuts, simone.g...@gmail.com
Thank you Alexandre! Problem solved :)

Alexandre Cesaro

unread,
Apr 12, 2016, 3:44:12 AM4/12/16
to Simone Giacomelli, golang-nuts
You're welcome, I updated Gomail so that the error message is clearer: https://github.com/go-gomail/gomail/commit/92eaa13340475e5341288c240e8c5745f1900a7e

elo...@gmail.com

unread,
May 30, 2016, 11:17:37 AM5/30/16
to golang-nuts
Hi there, if this is not the place to ask this question please be nice, I just followed the link from the Github page.

If I use Embed to embed an image for sending HTML mail, and in the HTML for the SetBody use cid:thenameoftheimage.png, the resulting sent email contains - and contains only the image, all other content is stripped out.  Any idea what I'm doing wrong?

- Geordie

Tong Sun

unread,
May 30, 2016, 9:41:28 PM5/30/16
to golang-nuts
Nice Alexandre. 

Can Gomail send email using SSL but not TLS? I.e., basically doing this:

Could you show me how to do it please? I looked at https://godoc.org/gopkg.in/gomail.v2, but haven't figured out the way. I also found a historic message with this:

 d := gomail.Dialer{Host: "localhost", Port: 587, SSL: false, TLSConfig: nil}

but it doesn't work (and there is no answer either). 

Please help. 
Thanks

On Wednesday, September 2, 2015 at 7:55:26 AM UTC-4, Alexandre Cesaro wrote:

Christian Mauduit

unread,
May 31, 2016, 1:26:27 AM5/31/16
to golan...@googlegroups.com
Hi,

If I read the documentation correctly, SetBody really "replaces any
content previously set by SetBody" so it makes sense the resulting sent
email contains only the image if you use SetBody with only
"cid:thenameoftheimage.png".

The code example in https://godoc.org/gopkg.in/gomail.v2#Message.Embed
shows some HTML code around the image ID :

`<img src="cid:image.jpg" alt="My image" />`

I suspect if you want to show the image and something else you should
try something like :

`<h1>Foo !</h1><img src="cid:thenameoftheimage.png"/><p>Bar bar bar bar
bar...</p>`

Have a nice day,

Christian.

On 05/30/2016 06:32 AM, elo...@gmail.com wrote:
> Hi there, if this is not the place to ask this question please be nice,
> I just followed the link from the Github page.
>
> If I use Embed to embed an image for sending HTML mail, and in the HTML
> for the SetBody use cid:thenameoftheimage.png, the resulting sent email
> contains - and contains *only* the image, all other content is stripped
> out. Any idea what I'm doing wrong?
>
> - Geordie

--
Christian Mauduit
uf...@ufoot.org
http://www.ufoot.org
int q = (2 * b) || !(2 * b);

Konstantin Khomoutov

unread,
May 31, 2016, 1:26:30 AM5/31/16
to elo...@gmail.com, golang-nuts
On Sun, 29 May 2016 21:32:15 -0700 (PDT)
elo...@gmail.com wrote:

> Hi there, if this is not the place to ask this question please be
> nice, I just followed the link from the Github page.
>
> If I use Embed to embed an image for sending HTML mail, and in the
> HTML for the SetBody use cid:thenameoftheimage.png, the resulting
> sent email contains - and contains *only* the image, all other
> content is stripped out. Any idea what I'm doing wrong?

Please try to provide an MCVE [1]. The question as stated means "I am
doing everything correctly but your package fails somewhere"; unless we
can examine the actual code which does not what you want it to do, we
can't tell what to blame: your approach to solve this task or the
package you're using.

1. http://stackoverflow.com/help/mcve

Geordie Guy

unread,
Jun 2, 2016, 12:47:22 AM6/2/16
to Christian Mauduit, golan...@googlegroups.com
Thanks heaps :)

Bernard LEGAUT

unread,
Jun 24, 2016, 10:10:37 AM6/24/16
to golang-nuts
I recently switch from go 1.5.1 to go 1.6, and gomail seems to get in trouble. 

Anyone with the same issue ?

Thanks,

Konstantin Khomoutov

unread,
Jun 24, 2016, 11:32:35 AM6/24/16
to Bernard LEGAUT, golang-nuts
On Fri, 24 Jun 2016 07:08:54 -0700 (PDT)
Bernard LEGAUT <b.le...@gmail.com> wrote:

> I recently switch from go 1.5.1 to go 1.6, and gomail seems to get in
> trouble.

What's the actual problem? People with strong telepathic skills are
rare and far in between.

Also, does `go get -u` for gomail solve the problem?
Does updating gomail to its "master"'s tip solve it?

ma...@alpha-force.net

unread,
Aug 10, 2016, 5:51:29 AM8/10/16
to golang-nuts
GitHub page says "Automatic encoding of special characters". Does that mean if I use output from (user provided input to a golang.org/pkg/text/template) as body input to gomail, gomail will properly escape any characters that could be used to insert SMTP headers or do anything else that could be malicious?

dipen...@continuum.net

unread,
Dec 27, 2016, 11:23:20 AM12/27/16
to golang-nuts
ALERT - After implementing Gomail v2 started getting lots of SPAM messages that ever received in Inbox. 

Michael Jones

unread,
Dec 27, 2016, 8:06:26 PM12/27/16
to dipen...@continuum.net, golang-nuts
post hoc, ergo propter hoc

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Michael T. Jones
michae...@gmail.com

emilyvyomaha...@gmail.com

unread,
Apr 13, 2017, 3:47:38 PM4/13/17
to golang-nuts
Hi Alexandre
I tried sending an email using the server settings from my outlook mailbox and got this error - Could you shed some light as to what this could be about? 

panic: read tcp 10.18.32.66:59347->10.12.137.20:3268: read: connection reset by peer


goroutine 1 [running]:

panic(0x1aaf80, 0xc420014460)

/usr/local/Cellar/go/1.7.4_2/libexec/src/runtime/panic.go:500 +0x1a1

main.main()

conne...@gmail.com

unread,
Jun 1, 2017, 4:36:37 PM6/1/17
to golang-nuts
Hey Alex, tried sending mail with gomail v2 having some ish.
here is my code:
func contact(w http.ResponseWriter, req *http.Request) {
       
var s string
       var e string
       var m string
       pd := pageData{
             
Title: "contact || CACCYE",
       }
       
if req.Method == http.MethodPost {
              s
= req.FormValue("subject")
              e
= req.FormValue("mail")
              m
= req.FormValue("message")

              pd
.subject = s
              pd
.email = e
              pd
.msg = m

              cb
:= gomail.NewMessage()
              cb
.SetHeader("From", e)
              cb
.SetHeader("To", "his_...@gmail.com", "her_...@gmail.com")
              cb
.SetHeader("Subject", s)
              cb
.SetBody("text/plain", m)

              d
:= gomail.NewDialer("smtp.gmail.com", 587, "my_...@gmail.com", "my_password")

             
// Send the email to Bob, Cora and Dan.
              if err := d.DialAndSend(cb); err != nil {
                     
panic(err)
             
}
       
}

       err
:= tpl.ExecuteTemplate(w, "contact.gohtml", pd)
       
if err != nil {
              log
.Println(err)
       
}
}

when i submit it outputs:
2017/06/01 19:28:48 http: panic serving [::1]:50340: dial tcp: i/o timeout
goroutine 6 [running]:
net/http.(*conn).serve.func1(0xc42008c6e0)
/usr/local/go/src/net/http/server.go:1721 +0xd0
panic(0x709800, 0xc4200165a0)
/usr/local/go/src/runtime/panic.go:489 +0x2cf
main.contact(0x8b6740, 0xc42013e2a0, 0xc42000ae00)
net/http.HandlerFunc.ServeHTTP(0x769658, 0x8b6740, 0xc42013e2a0, 0xc42000ae00)
/usr/local/go/src/net/http/server.go:1942 +0x44
net/http.(*ServeMux).ServeHTTP(0x8e38e0, 0x8b6740, 0xc42013e2a0, 0xc42000ae00)
/usr/local/go/src/net/http/server.go:2238 +0x130
net/http.serverHandler.ServeHTTP(0xc42011e0b0, 0x8b6740, 0xc42013e2a0, 0xc42000ae00)
/usr/local/go/src/net/http/server.go:2568 +0x92
net/http.(*conn).serve(0xc42008c6e0, 0x8b6d40, 0xc420018680)
/usr/local/go/src/net/http/server.go:1825 +0x612
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2668 +0x2ce
2017/06/01 19:28:54 http: panic serving [::1]:50370: 534 5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv-
5.7.14 DmuGszjeM-IZqxmuGU8tCESBHyOZpR73mPqkWEM8N_WNfGXS69r7GhgMhUleDP6K90OYsN
5.7.14 tlAP9aQdv9X7UaZk_Y4Yv0z-ZaJ6fYCNbsPQg-9MFT1hZw5UkZ9G-Cih5BTZ9XZzPNjbtM
5.7.14 a7KwOetlkIzo_gD2u-h-pTluI6tfdHfQ70ROvEPzD4VPPjbfIyC1_lOF3YLTCWUVrLYauZ
5.7.14 hC7MYnXwQJhuRf2wLOK6VAvtetjvk> Please log in via your web browser and
5.7.14 then try again.
5.7.14  Learn more at
5.7.14  https://support.google.com/mail/answer/78754 w11sm13739759eda.63 - gsmtp
goroutine 33 [running]:
net/http.(*conn).serve.func1(0xc4201361e0)
/usr/local/go/src/net/http/server.go:1721 +0xd0
panic(0x6fb7a0, 0xc42043f8e0)
/usr/local/go/src/runtime/panic.go:489 +0x2cf
main.contact(0x8b6740, 0xc4201442a0, 0xc420100b00)
net/http.HandlerFunc.ServeHTTP(0x769658, 0x8b6740, 0xc4201442a0, 0xc420100b00)
/usr/local/go/src/net/http/server.go:1942 +0x44
net/http.(*ServeMux).ServeHTTP(0x8e38e0, 0x8b6740, 0xc4201442a0, 0xc420100b00)
/usr/local/go/src/net/http/server.go:2238 +0x130
net/http.serverHandler.ServeHTTP(0xc42011e0b0, 0x8b6740, 0xc4201442a0, 0xc420100b00)
/usr/local/go/src/net/http/server.go:2568 +0x92
net/http.(*conn).serve(0xc4201361e0, 0x8b6d40, 0xc4200f2d40)
/usr/local/go/src/net/http/server.go:1825 +0x612
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2668 +0x2ce


hope to hear from you

antoni...@gmail.com

unread,
Jun 11, 2017, 10:47:54 AM6/11/17
to golang-nuts
Hey Alex,

Can gomail supports embedding a lot of images?

From
it seems that gomail only support embedding one image, if we embed a lot of them, there are still lots of tedious manual works to make it works. 

Right?

Tamás Gulácsi

unread,
Jun 11, 2017, 2:13:00 PM6/11/17
to golang-nuts
What do you mean by "lots of tedious manual works"?
You have to specify where shall those emails appear, (embed `<img src="cid:image.jpg" alt="My image" />` into the body),
or you can just Attach those files to the email.

yhj7...@163.com

unread,
Aug 24, 2017, 11:21:51 AM8/24/17
to golang-nuts
Hi, 
    Could you show me a method to set timeout when send a email?
Regards.

在 2015年9月2日星期三 UTC+8下午7:55:26,Alexandre Cesaro写道:

Tamás Gulácsi

unread,
Aug 24, 2017, 1:53:48 PM8/24/17
to golang-nuts
It uses a constant 10s timeout for dial. What should time out?

yhj7...@163.com

unread,
Aug 24, 2017, 9:41:57 PM8/24/17
to golang-nuts
Thank you very much for your reply. However, in my code, it spent 40s to send email. 

Here is the code:

now := time.Now()
msg := gomail.NewMessage()
//the element of msg is abridged
dial := gomail.Dialer{Host: "127.0.0.1", Port: 25}
dial.TLSConfig = &tls.Config{InsecureSkipVerify: true}
if err := dial.DialAndSend(msg); err != nil {
    log.Fatal("failed to send email", err)
} else {
    timeSpent := fmt.Sprintf("%.3f s", time.Since(now).Seconds())
    fmt.Println("time to spend in sending email", timeSpent )
}

在 2017年8月25日星期五 UTC+8上午1:53:48,Tamás Gulácsi写道:

Antonio Sun

unread,
Aug 25, 2017, 12:17:12 AM8/25/17
to golang-nuts
You should break that 40s up and see how long is spent on dial, and how long is spent on send. 

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/jMxZHzvvEVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.

yhj7...@163.com

unread,
Aug 27, 2017, 10:31:47 PM8/27/17
to golang-nuts
Whether there is a method to set timeout on dial and on send ?

Without setting timeout on sending, it spent 5 minutes to send an email. Badly, it will hang up, then cause bug on production.


在 2017年8月25日星期五 UTC+8下午12:17:12,Antonio Sun写道:
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

Tamás Gulácsi

unread,
Aug 28, 2017, 12:58:51 AM8/28/17
to golang-nuts
It's not settable now - you have to tweak the source.

Antonio Sun

unread,
Aug 28, 2017, 9:59:24 PM8/28/17
to yhj7...@163.com, golang-nuts
On Sun, Aug 27, 2017 at 10:31 PM, <yhj7...@163.com> wrote:

Without setting timeout on sending, it spent 5 minutes to send an email. Badly, it will hang up, then cause bug on production.

That means the mail server is busy. Setting shorter timeout will stress mail server even more and make things worse for everyone. 

The proper way is wait, and retry (dialing), with each retry waiting twice as long as before. So even if the remote mail server is down for a few hours, you email can still go through eventually. 


yhj7...@163.com

unread,
Aug 28, 2017, 10:05:11 PM8/28/17
to golang-nuts, yhj7...@163.com
Thanks very much.

But, what I mean of setting timeout is giving up this sending, and try to send another email


在 2017年8月29日星期二 UTC+8上午9:59:24,Antonio Sun写道:

sarb...@gmail.com

unread,
Aug 30, 2017, 8:44:49 AM8/30/17
to golang-nuts
Hello, Alexandre.

Thank you a lot for the package.

I have a question.
I have a slice for "To" field. The address is in a format like that: { "Сергей Сарбаш <xxxx...@ya.ru>", "Иван Петров <iv...@petrov.org>", ... }

If I assign it to the header it gets encoded and invalid:

gomail: could not send email 1: gomail: invalid address "=?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9_=D0=A1=D0=B0=D1=80=D0=B1?= =?UTF-8?q?=D0=B0=D1=88_<xxxx...@ya.ru>?=": mail: expected single address, got "?="

How to resolve that?
Thank you.

среда, 2 сентября 2015 г., 14:55:26 UTC+3 пользователь Alexandre Cesaro написал:

le...@stolaf.edu

unread,
Apr 10, 2018, 6:59:37 PM4/10/18
to golang-nuts
Is there a way to send an email AS a group member? Currently, I am able to do so via the Gmail Web Client. But I can't figure out a way to do it via my 3rd party client (Airmail 3), or standard Go (via net/smtp).

Hence, I was wondering if there was a way to send as a group.

axllo...@gmail.com

unread,
Apr 7, 2019, 2:10:13 AM4/7/19
to golang-nuts
hi, i use this code, I can't make it work help

Could you tell me how to properly use your library on this code, and set an example for a custom dealer, so that I can access the smtp through a proxy (sock4, sock4a, or sock5)? is it possible? please a couple of lines of code for an example

func main() {

   

   ch := make(chan *gomail.Message, 10)

   
// Use the channel in your program to send emails.
   m := gomail.NewMessage()
   
m.SetHeader("From", "ifabion...@mail.bcu.ac.uk")
   
m.SetHeader("To", "to@mail.com")
   //m.SetAddressHeader("Cc", "d...@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")

   ch <- m

   go func() {
     
d := gomail.NewDialer("smtp-mail.outlook.com", 587, "ifabion...@mail.bcu.ac.uk", "pwd")

     
var s gomail.SendCloser

      var err error
      open := false
      for {
         
select {
         
case m, ok := <-ch:
           
if !ok {
               
return
            }
           
if !open {
               
if s, err = d.Dial(); err != nil {
                 
panic(err)
               
}
               
open = true
            }
           
if err := gomail.Send(s, m); err != nil {
               
log.Print(err)
           
}
         
// Close the connection to the SMTP server if no email was sent in
         // the last 30 seconds.
         case <-time.After(30 * time.Second):
           
if open {
               
if err := s.Close(); err != nil {
                 
panic(err)
               
}
               
open = false
            }
         
}
     
}
   
}()

}




   
// Close the channel to stop the mail daemon.
   close(ch)


Michael Jones

unread,
Apr 7, 2019, 8:43:04 PM4/7/19
to axllo...@gmail.com, golang-nuts
If those black boxes represent Go language code, please share it here by pasting it into the Go Language Playground and then sharing a link in email here. 

It is impossible to understand these rectangles on my phone. 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

code veyper

unread,
Apr 8, 2019, 6:20:29 AM4/8/19
to golang-nuts


On Monday, April 8, 2019 at 3:43:04 AM UTC+3, Michael Jones wrote:
If those black boxes represent Go language code, please share it here by pasting it into the Go Language Playground and then sharing a link in email here. 

It is impossible to understand these rectangles on my phone. 
On Sat, Apr 6, 2019 at 11:10 PM <axllo...@gmail.com> wrote:
hi, i use this code, I can't make it work help

Could you tell me how to properly use your library on this code, and set an example for a custom dealer, so that I can access the smtp through a proxy (sock4, sock4a, or sock5)? is it possible? please a couple of lines of code for an example
func main() {

   

   ch := make(chan *gomail.Message, 10)

   
// Use the channel in your program to send emails.
   m := gomail.NewMessage()

   
m.SetHeader("From", "ifabio...@mail.bcu.ac.uk")

   
m.SetHeader("To", "to@mail.com")
   //m.SetAddressHeader("Cc", "d...@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")

   ch <- m

   go func() {

     
d := gomail.NewDialer("smtp-mail.outlook.com", 587, "ifabio...@mail.bcu.ac.uk", "pwd")
To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

lebedevni...@gmail.com

unread,
Jul 8, 2019, 1:46:40 PM7/8/19
to golang-nuts
Hello, from Russia. It would be nice to add a function for embed and attach file from byte array, not just from file


среда, 2 сентября 2015 г., 14:55:26 UTC+3 пользователь Alexandre Cesaro написал:
Hi,
Reply all
Reply to author
Forward
0 new messages