Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
Add SMTP_FROM environment variable to set the sender email address
Artem Sukhorukov2076ade3ff1d
diff --git a/app/server/email/email.go b/app/server/email/email.goindex 12bf8fdf..7dd4dabc 100644--- a/app/server/email/email.go+++ b/app/server/email/email.go@@ -57,18 +57,23 @@ func sendEmailViaSMTP(recipient, subject, htmlBody, textBody string) error {smtpPort := os.Getenv("SMTP_PORT")smtpUser := os.Getenv("SMTP_USER")smtpPassword := os.Getenv("SMTP_PASSWORD")+ smtpFrom := os.Getenv("SMTP_FROM")if smtpHost == "" || smtpPort == "" || smtpUser == "" || smtpPassword == "" {return fmt.Errorf("SMTP settings not found in environment variables")}+ if smtpFrom == "" {+ smtpFrom = smtpUser+ }+smtpAddress := fmt.Sprintf("%s:%s", smtpHost, smtpPort)auth := smtp.PlainAuth("", smtpUser, smtpPassword, smtpHost)// Generate a MIME boundaryboundary := "BOUNDARY1234567890"- header := fmt.Sprintf("From: %s\r\nTo: %s\r\nSubject: %s\r\nMIME-Version: 1.0\r\nContent-Type: multipart/alternative; boundary=\"%s\"\r\n\r\n", smtpUser, recipient, subject, boundary)+ header := fmt.Sprintf("From: %s\r\nTo: %s\r\nSubject: %s\r\nMIME-Version: 1.0\r\nContent-Type: multipart/alternative; boundary=\"%s\"\r\n\r\n", smtpFrom, recipient, subject, boundary)// Prepare the text body parttextPart := fmt.Sprintf("--%s\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\n%s\r\n", boundary, textBody)@@ -82,10 +87,10 @@ func sendEmailViaSMTP(recipient, subject, htmlBody, textBody string) error {// Combine the parts to form the full email messagemessage := []byte(header + textPart + htmlPart + endBoundary)- err := smtp.SendMail(smtpAddress, auth, smtpUser, []string{recipient}, message)+ err := smtp.SendMail(smtpAddress, auth, smtpFrom, []string{recipient}, message)if err != nil {return fmt.Errorf("error sending email via SMTP: %v", err)}return nil-}+}\ No newline at end of filediff --git a/guides/HOSTING.md b/guides/HOSTING.mdindex c1d611f0..67191296 100644--- a/guides/HOSTING.md+++ b/guides/HOSTING.md@@ -11,6 +11,7 @@ export SMTP_HOST=smtp.example.comexport SMTP_PORT=587export SMTP_USER=userexport SMTP_PASSWORD=password+export [email protected] # optional, if not set then SMTP_USER is used```Or, if you are using the `docker compose` option below, cp `app/_env` to `app/.env` and set the values in that file.