Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download api/pkg/emails/smtp_mailer_service.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/emails/smtp_mailer_service.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway/api/pkg/emails/smtp_mailer_service.go
-
curl -L -o smtp_mailer_service.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/emails/smtp_mailer_service.go
1.34 kB
| package emails | |
| import ( | |
| "context" | |
| "fmt" | |
| "net/smtp" | |
| "github.com/NdoleStudio/httpsms/pkg/telemetry" | |
| "github.com/NdoleStudio/stacktrace" | |
| mail "github.com/jordan-wright/email" | |
| ) | |
| // SMTPConfig is the config for setting up the smtpMailer | |
| type SMTPConfig struct { | |
| FromName string | |
| FromEmail string | |
| Username string | |
| Password string | |
| Hostname string | |
| Port string | |
| } | |
| type smtpMailer struct { | |
| address string | |
| from string | |
| tracer telemetry.Tracer | |
| auth smtp.Auth | |
| } | |
| // NewSMTPEmailService creates a new instance of the smtpMailer | |
| func NewSMTPEmailService(tracer telemetry.Tracer, config SMTPConfig) Mailer { | |
| return &smtpMailer{ | |
| tracer: tracer, | |
| auth: smtp.PlainAuth("", config.Username, config.Password, config.Hostname), | |
| address: fmt.Sprintf("%s:%s", config.Hostname, config.Port), | |
| from: fmt.Sprintf("%s <%s>", config.FromName, config.FromEmail), | |
| } | |
| } | |
| // Send a new email | |
| func (mailer *smtpMailer) Send(ctx context.Context, email *Email) (err error) { | |
| ctx, span := mailer.tracer.Start(ctx) | |
| defer span.End() | |
| e := mail.NewEmail() | |
| e.From = mailer.from | |
| e.To = []string{email.toAddress()} | |
| e.Subject = email.Subject | |
| e.Text = []byte(email.Text) | |
| e.HTML = []byte(email.HTML) | |
| err = e.Send(mailer.address, mailer.auth) | |
| if err != nil { | |
| return stacktrace.Propagatef(err, "cannot send email") | |
| } | |
| return nil | |
| } | |