Implement HELLO_HOSTNAME runtime configuration variable
This commit is contained in:
		
							parent
							
								
									ca42b4aeab
								
							
						
					
					
						commit
						08024e2ad7
					
				|  | @ -67,6 +67,7 @@ docker-compose up | |||
| | `SMTP_PASSWORD`             | The SMTP user password                                                                                                                                       | N/A                                | | ||||
| | `SMTP_AUTH_TYPE`            | The SMTP authentication type. Possible values: `PLAIN`, `LOGIN`, `NONE`                                                                                      | `NONE`                             | | ||||
| | `SMTP_ENCRYPTION`           | the encryption method. Possible values: `NONE`, `SSL`, `SSLTLS`, `TLS`, `STARTTLS`                                                                           | `STARTTLS`                         | | ||||
| | `HELLO_HOSTNAME`            | Hostname to use for the hello message. smtp-relay.gmail.com needs this set to anything but `localhost`                                                       | `localhost`                        | | ||||
| 
 | ||||
| ### Defaults for server configuration | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,6 +13,7 @@ type SmtpMail struct { | |||
| 	port       int | ||||
| 	username   string | ||||
| 	password   string | ||||
| 	helloHostName string | ||||
| 	authType   mail.AuthType | ||||
| 	encryption mail.Encryption | ||||
| 	noTLSCheck bool | ||||
|  | @ -46,8 +47,8 @@ func encryptionType(encryptionType string) mail.Encryption { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func NewSmtpMail(hostname string, port int, username string, password string, noTLSCheck bool, auth string, fromName, from string, encryption string) *SmtpMail { | ||||
| 	ans := SmtpMail{hostname: hostname, port: port, username: username, password: password, noTLSCheck: noTLSCheck, fromName: fromName, from: from, authType: authType(auth), encryption: encryptionType(encryption)} | ||||
| func NewSmtpMail(hostname string, port int, username string, password string, helloHostName string, noTLSCheck bool, auth string, fromName, from string, encryption string) *SmtpMail { | ||||
| 	ans := SmtpMail{hostname: hostname, port: port, username: username, password: password, helloHostName: helloHostName, noTLSCheck: noTLSCheck, fromName: fromName, from: from, authType: authType(auth), encryption: encryptionType(encryption)} | ||||
| 	return &ans | ||||
| } | ||||
| 
 | ||||
|  | @ -66,6 +67,7 @@ func (o *SmtpMail) Send(toName string, to string, subject string, content string | |||
| 	server.Authentication = o.authType | ||||
| 	server.Username = o.username | ||||
| 	server.Password = o.password | ||||
| 	server.Helo = o.helloHostName | ||||
| 	server.Encryption = o.encryption | ||||
| 	server.KeepAlive = false | ||||
| 	server.ConnectTimeout = 10 * time.Second | ||||
|  |  | |||
							
								
								
									
										5
									
								
								main.go
								
								
								
								
							
							
						
						
									
										5
									
								
								main.go
								
								
								
								
							|  | @ -30,6 +30,7 @@ var ( | |||
| 	flagBindAddress    string = "0.0.0.0:5000" | ||||
| 	flagSmtpHostname   string = "127.0.0.1" | ||||
| 	flagSmtpPort       int    = 25 | ||||
| 	flagHelloHostName  string = "localhost" | ||||
| 	flagSmtpUsername   string | ||||
| 	flagSmtpPassword   string | ||||
| 	flagSmtpAuthType   string = "NONE" | ||||
|  | @ -72,6 +73,7 @@ func init() { | |||
| 	flag.StringVar(&flagBindAddress, "bind-address", util.LookupEnvOrString("BIND_ADDRESS", flagBindAddress), "Address:Port to which the app will be bound.") | ||||
| 	flag.StringVar(&flagSmtpHostname, "smtp-hostname", util.LookupEnvOrString("SMTP_HOSTNAME", flagSmtpHostname), "SMTP Hostname") | ||||
| 	flag.IntVar(&flagSmtpPort, "smtp-port", util.LookupEnvOrInt("SMTP_PORT", flagSmtpPort), "SMTP Port") | ||||
| 	flag.StringVar(&flagHelloHostName, "hello-hostname", util.LookupEnvOrString("HELLO_HOSTNAME", flagHelloHostName), "Hello HostName") | ||||
| 	flag.StringVar(&flagSmtpUsername, "smtp-username", util.LookupEnvOrString("SMTP_USERNAME", flagSmtpUsername), "SMTP Username") | ||||
| 	flag.StringVar(&flagSmtpPassword, "smtp-password", util.LookupEnvOrString("SMTP_PASSWORD", flagSmtpPassword), "SMTP Password") | ||||
| 	flag.BoolVar(&flagSmtpNoTLSCheck, "smtp-no-tls-check", util.LookupEnvOrBool("SMTP_NO_TLS_CHECK", flagSmtpNoTLSCheck), "Disable TLS verification for SMTP. This is potentially dangerous.") | ||||
|  | @ -94,6 +96,7 @@ func init() { | |||
| 	util.BindAddress = flagBindAddress | ||||
| 	util.SmtpHostname = flagSmtpHostname | ||||
| 	util.SmtpPort = flagSmtpPort | ||||
| 	util.HelloHostName = flagHelloHostName | ||||
| 	util.SmtpUsername = flagSmtpUsername | ||||
| 	util.SmtpPassword = flagSmtpPassword | ||||
| 	util.SmtpAuthType = flagSmtpAuthType | ||||
|  | @ -176,7 +179,7 @@ func main() { | |||
| 	if util.SendgridApiKey != "" { | ||||
| 		sendmail = emailer.NewSendgridApiMail(util.SendgridApiKey, util.EmailFromName, util.EmailFrom) | ||||
| 	} else { | ||||
| 		sendmail = emailer.NewSmtpMail(util.SmtpHostname, util.SmtpPort, util.SmtpUsername, util.SmtpPassword, util.SmtpNoTLSCheck, util.SmtpAuthType, util.EmailFromName, util.EmailFrom, util.SmtpEncryption) | ||||
| 		sendmail = emailer.NewSmtpMail(util.SmtpHostname, util.SmtpPort, util.SmtpUsername, util.SmtpPassword, util.HelloHostName, util.SmtpNoTLSCheck, util.SmtpAuthType, util.EmailFromName, util.EmailFrom, util.SmtpEncryption) | ||||
| 	} | ||||
| 
 | ||||
| 	app.GET(util.BasePath+"/test-hash", handler.GetHashesChanges(db), handler.ValidSession) | ||||
|  |  | |||
|  | @ -10,6 +10,7 @@ var ( | |||
| 	SmtpPort       int | ||||
| 	SmtpUsername   string | ||||
| 	SmtpPassword   string | ||||
| 	HelloHostName  string | ||||
| 	SmtpNoTLSCheck bool | ||||
| 	SmtpEncryption string | ||||
| 	SmtpAuthType   string | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue