bytebase/bytebase · error

MAIL FROM failed

Error message

MAIL FROM failed

What it means

The SMTP server rejected the MAIL FROM command with the configured envelope sender address (s.from). The wrapped error carries the server's 5xx/4xx response. This happens before any recipient is transmitted, so it indicates the server refuses the sender, not the recipient.

Source

Thrown at backend/plugin/mailer/smtp.go:55

		return errors.Wrapf(err, "failed to connect to SMTP server %s", addr)
	}
	defer client.Close()

	if s.config.Encryption == storepb.EmailSetting_SMTPConfig_STARTTLS {
		tlsConfig := &tls.Config{ServerName: s.config.Host}
		if err := client.StartTLS(tlsConfig); err != nil {
			return errors.Wrap(err, "STARTTLS failed")
		}
	}

	if auth := s.auth(); auth != nil {
		if err := client.Auth(auth); err != nil {
			return errors.Wrap(err, "SMTP authentication failed")
		}
	}

	if err := client.Mail(s.from); err != nil {
		return errors.Wrap(err, "MAIL FROM failed")
	}
	for _, to := range req.To {
		if err := client.Rcpt(to); err != nil {
			return errors.Wrapf(err, "RCPT TO %s failed", to)
		}
	}

	w, err := client.Data()
	if err != nil {
		return errors.Wrap(err, "DATA command failed")
	}
	msg := s.buildMessage(req)
	if _, err := w.Write([]byte(msg)); err != nil {
		return errors.Wrap(err, "failed to write message")
	}
	if err := w.Close(); err != nil {
		return errors.Wrap(err, "failed to close data writer")
	}

View on GitHub (pinned to 1870550677)

Solutions

  1. Set From to an address verified/authorized with the SMTP provider (match the authenticated account for Gmail/M365).
  2. Complete domain/address verification in the provider console (SES identity, SendGrid sender authentication).
  3. Check the wrapped SMTP response code for the exact rejection reason and fix accordingly.
  4. Validate the From address syntax in settings (no spaces, proper user@domain format).

Example fix

// before: unverified sender domain
From: "bytebase@random-domain.net"
// after
From: "bytebase@verified-company-domain.com"
Defensive patterns

Strategy: validation

Validate before calling

import "net/mail"
func fromAddressValid(from string) bool {
    _, err := mail.ParseAddress(from)
    return err == nil
}
// plus: confirm From domain is verified with the SMTP provider before first send

Try / catch

if err := sender.Send(ctx, req); err != nil {
    if strings.Contains(err.Error(), "MAIL FROM failed") {
        // surface wrapped SMTP response; check sender authorization on the provider
    }
}

Prevention

When it happens

Trigger: Send called with s.from not accepted by the server: address not authorized for the authenticated user, malformed address, or relay denial for unauthenticated senders.

Common situations: From address domain not verified with the SMTP provider (SES, SendGrid domain verification); M365/Gmail rejecting a From different from the authenticated account; empty or malformed From in email settings; server restricts MAIL FROM to specific verified identities.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/82fd69f59d0383ad. Report an issue: GitHub.