Gomail v2 dial tcp: i/o timeout

i'm using gomail v2 to send email to my member and then using docker to run my service.

but when i hit the api that host my sendemail function i get this error

dial tcp: i/o timeout

here's my code

func (cc *UserController) ForgetPassword(ctx *gin.Context)  {



    msg := "forget pass link: forgetpasslink.com"

    mailer := gomail.NewMessage()
    mailer.SetHeader("From", "[email protected]")
    mailer.SetHeader("To", "[email protected]")
    mailer.SetAddressHeader("Cc", "[email protected]", "ADMIN")
    mailer.SetHeader("Subject", "test email")
    mailer.SetBody("text/plain", msg)

    dialer := gomail.NewDialer(
        "smtp.google.com",
        587,
        "[email protected]",
        "emailpass",
    )

    err = dialer.DialAndSend(mailer)

    if err != nil {
        ctx.JSON(http.StatusBadRequest, err.Error())
        return
    }

    return
}

Upvotes: 2

Views: 2501

Answers (1)

Jeff Modell
Jeff Modell

Reputation: 51

Seems to be a problem running it in docker or ubuntu. (https://github.com/go-gomail/gomail/issues/80 -- though the linked issue is from 2017...)

I am working on an application where it runs fine locally, but I get the same dial tcp //ip i/o timeout when deployed via docker on a ubuntu server.

When I comment out the mail functionality, it works fine.

Can you let us know if you came up with a solution?

Upvotes: 0

Related Questions