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
--
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.
--
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
--
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
--
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)
}
d := gomail.Dialer{Host: "localhost", Port: 587, SSL: false, TLSConfig: nil}
--
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.
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()
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)
}
}
2017/06/01 19:28:48 http: panic serving [::1]:50340: dial tcp: i/o timeoutgoroutine 6 [running]:net/http.(*conn).serve.func1(0xc42008c6e0) /usr/local/go/src/net/http/server.go:1721 +0xd0panic(0x709800, 0xc4200165a0) /usr/local/go/src/runtime/panic.go:489 +0x2cfmain.contact(0x8b6740, 0xc42013e2a0, 0xc42000ae00) /home/connelblaze/go/src/github.com/connelevalsam/GoWebDev/001/src/sendmail/src/main/main.go:86 +0x5d3net/http.HandlerFunc.ServeHTTP(0x769658, 0x8b6740, 0xc42013e2a0, 0xc42000ae00) /usr/local/go/src/net/http/server.go:1942 +0x44net/http.(*ServeMux).ServeHTTP(0x8e38e0, 0x8b6740, 0xc42013e2a0, 0xc42000ae00) /usr/local/go/src/net/http/server.go:2238 +0x130net/http.serverHandler.ServeHTTP(0xc42011e0b0, 0x8b6740, 0xc42013e2a0, 0xc42000ae00) /usr/local/go/src/net/http/server.go:2568 +0x92net/http.(*conn).serve(0xc42008c6e0, 0x8b6d40, 0xc420018680) /usr/local/go/src/net/http/server.go:1825 +0x612created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2668 +0x2ce2017/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_WNfGXS69r7GhgMhUleDP6K90OYsN5.7.14 tlAP9aQdv9X7UaZk_Y4Yv0z-ZaJ6fYCNbsPQg-9MFT1hZw5UkZ9G-Cih5BTZ9XZzPNjbtM5.7.14 a7KwOetlkIzo_gD2u-h-pTluI6tfdHfQ70ROvEPzD4VPPjbfIyC1_lOF3YLTCWUVrLYauZ5.7.14 hC7MYnXwQJhuRf2wLOK6VAvtetjvk> Please log in via your web browser and5.7.14 then try again.5.7.14 Learn more at5.7.14 https://support.google.com/mail/answer/78754 w11sm13739759eda.63 - gsmtpgoroutine 33 [running]:net/http.(*conn).serve.func1(0xc4201361e0) /usr/local/go/src/net/http/server.go:1721 +0xd0panic(0x6fb7a0, 0xc42043f8e0) /usr/local/go/src/runtime/panic.go:489 +0x2cfmain.contact(0x8b6740, 0xc4201442a0, 0xc420100b00) /home/connelblaze/go/src/github.com/connelevalsam/GoWebDev/001/src/sendmail/src/main/main.go:86 +0x5d3net/http.HandlerFunc.ServeHTTP(0x769658, 0x8b6740, 0xc4201442a0, 0xc420100b00) /usr/local/go/src/net/http/server.go:1942 +0x44net/http.(*ServeMux).ServeHTTP(0x8e38e0, 0x8b6740, 0xc4201442a0, 0xc420100b00) /usr/local/go/src/net/http/server.go:2238 +0x130net/http.serverHandler.ServeHTTP(0xc42011e0b0, 0x8b6740, 0xc4201442a0, 0xc420100b00) /usr/local/go/src/net/http/server.go:2568 +0x92net/http.(*conn).serve(0xc4201361e0, 0x8b6d40, 0xc4200f2d40) /usr/local/go/src/net/http/server.go:1825 +0x612created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2668 +0x2ce
--
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.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
Without setting timeout on sending, it spent 5 minutes to send an email. Badly, it will hang up, then cause bug on production.
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)
--
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.
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 helpCould 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.
Hi,
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.