Error connecting to SMTP Server: "either ServerName or InsecureSkipVerify must be specified in the tls.Config" #569

Closed
opened 2020-05-27 10:46:26 +00:00 by Jrester · 4 comments

The api fails with the following error when it tries to send a mail. The SMTP config is correct as it works with other applications and the gomail test snippet. I am not sure if this a problem with my setup, vikunja or gomail.

Error

api_1    | 2020-05-27T12:23:36.502633864+02:00: ERROR	▶ mail/func1 03b Error during connect to smtp server: %s tls: either ServerName or InsecureSkipVerify must be specified in the tls.Config
api_1    | panic: runtime error: invalid memory address or nil pointer dereference
api_1    | [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x9e4674]
api_1    | 
api_1    | goroutine 10 [running]:
api_1    | gopkg.in/gomail%2ev2.send(0x0, 0x0, 0x4000314b40, 0x9ef2a4, 0x40002d0100)
api_1    | 	/go/src/code.vikunja.io/api/vendor/gopkg.in/gomail.v2/send.go:57 +0x6c
api_1    | gopkg.in/gomail%2ev2.Send(0x0, 0x0, 0x4000565f60, 0x1, 0x1, 0x2, 0x4000000180)
api_1    | 	/go/src/code.vikunja.io/api/vendor/gopkg.in/gomail.v2/send.go:38 +0x5c
api_1    | code.vikunja.io/api/pkg/mail.StartMailDaemon.func1()
api_1    | 	/go/src/code.vikunja.io/api/pkg/mail/mail.go:63 +0x484
api_1    | created by code.vikunja.io/api/pkg/mail.StartMailDaemon
api_1    | 	/go/src/code.vikunja.io/api/pkg/mail/mail.go:43 +0x164

Config

mailer:
  # Whether to enable the mailer or not. If it is disabled, all users are enabled right away and password reset is not possible.
  enabled: true
  # SMTP Host
  host: "smtp.xxx.xxx"
  # SMTP Host port
  port: 587
  # SMTP username
  username: "xxx@xxx.xxx"
  # SMTP password
  password: "xxx
  # Wether to skip verification of the tls certificate on the server
  skiptlsverify: false
  # The default from address when sending emails
  fromemail: "xxx@xxx.xxx"
  # The length of the mail queue.
  queuelength: 100
  # The timeout in seconds after which the current open connection to the mailserver will be closed.
  queuetimeout: 30

Test

The following code works, but only when ServerName is also specified otherwise it will fail with the same error as vikunja. But in vikunja InsecureSkipVerify should be set to true and as such not require ServerName.

package main

import (
	"crypto/tls"

	"gopkg.in/gomail.v2"
)

func main() {
	m := gomail.NewMessage()
	m.SetHeader("From", "xxx@xxx.xxx")
	m.SetHeader("To", "xxx@xxx.xxx")
	m.SetHeader("Subject", "Test")
	m.SetBody("text/html", "Test")

	d := gomail.NewDialer("smtp.xxx.xxx", 587, "xxx@xxx.xxx", "xxx")
	d.TLSConfig = &tls.Config{InsecureSkipVerify: false, ServerName: "smtp.xxx.xxx"}
	if err := d.DialAndSend(m); err != nil {
		panic(err)
	}
}

The api fails with the following error when it tries to send a mail. The SMTP config is correct as it works with other applications and the gomail test snippet. I am not sure if this a problem with my setup, vikunja or gomail. ### Error ``` api_1 | 2020-05-27T12:23:36.502633864+02:00: ERROR ▶ mail/func1 03b Error during connect to smtp server: %s tls: either ServerName or InsecureSkipVerify must be specified in the tls.Config api_1 | panic: runtime error: invalid memory address or nil pointer dereference api_1 | [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x9e4674] api_1 | api_1 | goroutine 10 [running]: api_1 | gopkg.in/gomail%2ev2.send(0x0, 0x0, 0x4000314b40, 0x9ef2a4, 0x40002d0100) api_1 | /go/src/code.vikunja.io/api/vendor/gopkg.in/gomail.v2/send.go:57 +0x6c api_1 | gopkg.in/gomail%2ev2.Send(0x0, 0x0, 0x4000565f60, 0x1, 0x1, 0x2, 0x4000000180) api_1 | /go/src/code.vikunja.io/api/vendor/gopkg.in/gomail.v2/send.go:38 +0x5c api_1 | code.vikunja.io/api/pkg/mail.StartMailDaemon.func1() api_1 | /go/src/code.vikunja.io/api/pkg/mail/mail.go:63 +0x484 api_1 | created by code.vikunja.io/api/pkg/mail.StartMailDaemon api_1 | /go/src/code.vikunja.io/api/pkg/mail/mail.go:43 +0x164 ``` ### Config ``` mailer: # Whether to enable the mailer or not. If it is disabled, all users are enabled right away and password reset is not possible. enabled: true # SMTP Host host: "smtp.xxx.xxx" # SMTP Host port port: 587 # SMTP username username: "xxx@xxx.xxx" # SMTP password password: "xxx # Wether to skip verification of the tls certificate on the server skiptlsverify: false # The default from address when sending emails fromemail: "xxx@xxx.xxx" # The length of the mail queue. queuelength: 100 # The timeout in seconds after which the current open connection to the mailserver will be closed. queuetimeout: 30 ``` ### Test The following code works, but only when `ServerName` is also specified otherwise it will fail with the same error as vikunja. But in vikunja `InsecureSkipVerify` should be set to `true` and as such not require `ServerName`. ``` package main import ( "crypto/tls" "gopkg.in/gomail.v2" ) func main() { m := gomail.NewMessage() m.SetHeader("From", "xxx@xxx.xxx") m.SetHeader("To", "xxx@xxx.xxx") m.SetHeader("Subject", "Test") m.SetBody("text/html", "Test") d := gomail.NewDialer("smtp.xxx.xxx", 587, "xxx@xxx.xxx", "xxx") d.TLSConfig = &tls.Config{InsecureSkipVerify: false, ServerName: "smtp.xxx.xxx"} if err := d.DialAndSend(m); err != nil { panic(err) } } ```
Owner

That's an interesting error, I'll take a look. It could be I just missed ServerName in the TLSConfig option of gomailer.

I'll also add a cli command to be able to debug this more easy.

That's an interesting error, I'll take a look. It could be I just missed `ServerName` in the `TLSConfig` option of gomailer. I'll also add a cli command to be able to debug this more easy.
Owner

Test PR is up: #571

I've also included a possible fix in it which made the error go away in my tests.

Test PR is up: #571 I've also included a possible fix in it which made the error go away in my tests.
konrad reopened this issue 2020-05-29 13:10:21 +00:00
Author

Great, Thanks! Verified the PR works.

Great, Thanks! Verified the PR works.
Owner

Great!

I'll close this issue since it is resolved and the fix already merged in master. Feel free to reopen this or another one.

Great! I'll close this issue since it is resolved and the fix already merged in master. Feel free to reopen this or another one.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: vikunja/vikunja#569
No description provided.