R
Railway•12mo ago
Rozukai

Namecheap SMTP return error

Hi everyone, In my golang app, I try to connect to namecheap private email service using the specified settings here : https://www.namecheap.com/support/knowledgebase/article.aspx/1179/2175/general-private-email-configuration-for-mail-clients-and-mobile-devices/ But I got this error : 2023/12/19 15:05:59 read tcp 172.17.2.105:50178->198.54.122.135:465: read: connection reset by peer Here is my golang code :
emailTemplate, _ := template.ParseFiles(fmt.Sprintf("%s/%s", useCase.templateSettings.TemplatePath, "sign-in.email.html"))

var body bytes.Buffer

mimeHeaders := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
body.Write([]byte(fmt.Sprintf("Subject: Verify your email \n%s\n\n", mimeHeaders)))
err = emailTemplate.Execute(&body, struct {
Callback string
}{
Callback: fmt.Sprintf("%s?email=%s&uniqId=%s", useCase.verifyEmailSettings.CallbackBaseUrl, message.Email, uniqId.String()),
})
if err != nil {
return errors.NewInternalError("Error while sending verification email", err)
}

smtpAuth := smtp.PlainAuth("", useCase.smtpSettings.Username, useCase.smtpSettings.Password, useCase.smtpSettings.Host)
err = smtp.SendMail(useCase.smtpSettings.Host+":"+useCase.smtpSettings.Port, smtpAuth, useCase.smtpSettings.Username, []string{message.Email}, body.Bytes())
if err != nil {
return errors.NewInternalError("Error while sending verification email", err)
}
emailTemplate, _ := template.ParseFiles(fmt.Sprintf("%s/%s", useCase.templateSettings.TemplatePath, "sign-in.email.html"))

var body bytes.Buffer

mimeHeaders := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
body.Write([]byte(fmt.Sprintf("Subject: Verify your email \n%s\n\n", mimeHeaders)))
err = emailTemplate.Execute(&body, struct {
Callback string
}{
Callback: fmt.Sprintf("%s?email=%s&uniqId=%s", useCase.verifyEmailSettings.CallbackBaseUrl, message.Email, uniqId.String()),
})
if err != nil {
return errors.NewInternalError("Error while sending verification email", err)
}

smtpAuth := smtp.PlainAuth("", useCase.smtpSettings.Username, useCase.smtpSettings.Password, useCase.smtpSettings.Host)
err = smtp.SendMail(useCase.smtpSettings.Host+":"+useCase.smtpSettings.Port, smtpAuth, useCase.smtpSettings.Username, []string{message.Email}, body.Bytes())
if err != nil {
return errors.NewInternalError("Error while sending verification email", err)
}
SMTP connexion can be done on Railway ?
7 Replies
Percy
Percy•12mo ago
Project ID: 62a7d631-15d2-4bde-a633-b2e28b306105
Rozukai
RozukaiOP•12mo ago
62a7d631-15d2-4bde-a633-b2e28b306105
Brody
Brody•12mo ago
does this work locally?
Rozukai
RozukaiOP•12mo ago
Yes it works, I've also contacted namecheap support and they answer me this : "Per our check, the SPF record for Private Email is affected by the CNAME record @ <XXX>.up.railway.app.). SPF (Sender Policy Framework) is a DNS text entry that shows a list of servers that should be considered allowed to send mail for a specific domain. The absence of the SPF record may negatively affect the deliverability of your emails. You may change the record "TYPE" in the current CNAME record with Host "@" <XXX>.up.railway.app. from CNAME to ALIAS(if the service provider where the domain connected works with this type of record (ALIAS)" Do you think if I change CNAME to ALIAS it will cause trouble for my website ?
Brody
Brody•12mo ago
yes it absolutely will, but I don't see how the domain of your website has anything to do with smtp, I think they've just given you a f**k off answer it's likely they've blocked connection attempts from GCP IP address because they've delt with spam from GCP workloads before I've had zero issues sending emails with a Zoho email address on railway, might be worth to switch?
Rozukai
RozukaiOP•12mo ago
I will check how it works 😉 Thanks for the tips
Brody
Brody•12mo ago
it just works, at least all the times I've used it
Want results from more Discord servers?
Add your server