Hi,

I set a timeout of 20 sec for the Dialer, but the DialAndSend continued 
beyond the timeout and sent email after 27sec.

code:
dialer = gomail.NewDialer("smtp.mailtrap.io", 587, u, p)
dialer.Timeout = 20*time.Second

start := time.Now()
if err = dialer.DialAndSend(m); err != nil {
    err = fmt.Errorf("sendEmail: sending email to %s; %s", u.email, err)
    return
}
elapsed := time.Since(start)
lgr.Trace().Msgf("EML %11.6fms", float64(elapsed)/float64(time.Millisecond))


Log message:
2/28 06:41:00.325 TRC EML 27604.141065ms remote=172.19.0.1
On Friday, August 25, 2017 at 9:47:12 AM UTC+5:30 Antonio Sun wrote:

> You should break that 40s up and see how long is spent on dial, and how 
> long is spent on send. 
>
> On Thu, Aug 24, 2017 at 9:41 PM, <yhj7...@163.com> wrote:
>
>> 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写道:
>>
>>> It uses a constant 10s timeout for dial. What should time out?
>>
>> -- 
>> 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+unsubscr...@googlegroups.com.
>>
>
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/80c3ebbb-ee60-4e6f-9a29-7456bb8d94ban%40googlegroups.com.

Reply via email to