smtp

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package smtp provides SMTP definitions and functions shared between smtpserver and smtpclient.

Index

Constants

This section is empty.

Variables

View Source
var (
	C211SystemStatus = 211
	C214Help         = 214
	C220ServiceReady = 220
	C221Closing      = 221
	C235AuthSuccess  = 235 // ../rfc/4954:573

	C250Completed               = 250
	C251UserNotLocalWillForward = 251
	C252WithoutVrfy             = 252

	C334ContinueAuth = 334 // ../rfc/4954:187
	C354Continue     = 354

	C421ServiceUnavail         = 421
	C432PasswdTransitionNeeded = 432 // ../rfc/4954:578
	C454TempAuthFail           = 454 // ../rfc/4954:586
	C450MailboxUnavail         = 450
	C451LocalErr               = 451
	C452StorageFull            = 452 // Also for "too many recipients", ../rfc/5321:3576
	C455BadParams              = 455

	C500BadSyntax              = 500
	C501BadParamSyntax         = 501
	C502CmdNotImpl             = 502
	C503BadCmdSeq              = 503
	C504ParamNotImpl           = 504
	C521HostNoMail             = 521 // ../rfc/7504:179
	C530SecurityRequired       = 530 // ../rfc/3207:148 ../rfc/4954:623
	C534AuthMechWeak           = 534 // ../rfc/4954:593
	C535AuthBadCreds           = 535 // ../rfc/4954:600
	C538EncReqForAuth          = 538 // ../rfc/4954:630
	C550MailboxUnavail         = 550
	C551UserNotLocal           = 551
	C552MailboxFull            = 552
	C553BadMailbox             = 553
	C554TransactionFailed      = 554
	C555UnrecognizedAddrParams = 555
	C556DomainNoMail           = 556 // ../rfc/7504:207
)

Reply codes.

View Source
var (
	// 0.x - Other or Undefined Status.
	// ../rfc/3463:287
	SeOther00 = "0.0"

	// 1.x - Address.
	// ../rfc/3463:295
	SeAddr1Other0                  = "1.0"
	SeAddr1UnknownDestMailbox1     = "1.1"
	SeAddr1UnknownSystem2          = "1.2"
	SeAddr1MailboxSyntax3          = "1.3"
	SeAddr1MailboxAmbiguous4       = "1.4"
	SeAddr1DestValid5              = "1.5" // For success responses.
	SeAddr1DestMailboxMoved6       = "1.6"
	SeAddr1SenderSyntax7           = "1.7"
	SeAddr1BadSenderSystemAddress8 = "1.8"
	SeAddr1NullMX                  = "1.10" // ../rfc/7505:237

	// 2.x - Mailbox.
	// ../rfc/3463:361
	SeMailbox2Other0             = "2.0"
	SeMailbox2Disabled1          = "2.1"
	SeMailbox2Full2              = "2.2"
	SeMailbox2MsgLimitExceeded3  = "2.3"
	SeMailbox2MailListExpansion4 = "2.4"

	// 3.x - Mail system.
	// ../rfc/3463:405
	SeSys3Other0            = "3.0"
	SeSys3StorageFull1      = "3.1"
	SeSys3NotAccepting2     = "3.2"
	SeSys3NotSupported3     = "3.3"
	SeSys3MsgLimitExceeded4 = "3.4"
	SeSys3Misconfigured5    = "3.5"

	// 4.x - Network and routing.
	// ../rfc/3463:455
	SeNet4Other0           = "4.0"
	SeNet4NoAnswer1        = "4.1"
	SeNet4BadConn2         = "4.2"
	SeNet4Name3            = "4.3"
	SeNet4Routing4         = "4.4"
	SeNet4Congestion5      = "4.5"
	SeNet4Loop6            = "4.6"
	SeNet4DeliveryExpired7 = "4.7"

	// 5.x - Mail delivery protocol.
	// ../rfc/3463:527
	SeProto5Other0              = "5.0"
	SeProto5BadCmdOrSeq1        = "5.1"
	SeProto5Syntax2             = "5.2"
	SeProto5TooManyRcpts3       = "5.3"
	SeProto5BadParams4          = "5.4"
	SeProto5ProtocolMismatch5   = "5.5"
	SeProto5AuthExchangeTooLong = "5.6" // ../rfc/4954:650

	// 6.x - Message content/media.
	// ../rfc/3463:579
	SeMsg6Other0                    = "6.0"
	SeMsg6MediaUnsupported1         = "6.1"
	SeMsg6ConversionProhibited2     = "6.2"
	SeMsg6ConversionUnsupported3    = "6.3"
	SeMsg6ConversionWithLoss4       = "6.4"
	SeMsg6ConversionFailed5         = "6.5"
	SeMsg6NonASCIIAddrNotPermitted7 = "6.7" // ../rfc/6531:735
	SeMsg6UTF8ReplyRequired8        = "6.8" // ../rfc/6531:746
	SeMsg6UTF8CannotTransfer9       = "6.9" // ../rfc/6531:758

	// 7.x - Security/policy.
	// ../rfc/3463:628
	SePol7Other0                = "7.0"
	SePol7DeliveryUnauth1       = "7.1"
	SePol7ExpnProhibited2       = "7.2"
	SePol7ConversionImpossible3 = "7.3"
	SePol7Unsupported4          = "7.4"
	SePol7CryptoFailure5        = "7.5"
	SePol7CryptoUnsupported6    = "7.6"
	SePol7MsgIntegrity7         = "7.7"
	SePol7AuthBadCreds8         = "7.8"  // ../rfc/4954:600
	SePol7AuthWeakMech9         = "7.9"  // ../rfc/4954:593
	SePol7EncNeeded10           = "7.10" // ../rfc/5248:359
	SePol7EncReqForAuth11       = "7.11" // ../rfc/4954:630
	SePol7PasswdTransitionReq12 = "7.12" // ../rfc/4954:578
	SePol7AccountDisabled13     = "7.13" // ../rfc/5248:399
	SePol7TrustReq14            = "7.14" // ../rfc/5248:418
	// todo spec: duplicate spec of 7.16 ../rfc/4865:412 ../rfc/6710:878
	// todo spec: duplicate spec of 7.17 ../rfc/4865:418 ../rfc/7293:1137
	SePol7NoDKIMPass20        = "7.20" // ../rfc/7372:137
	SePol7NoDKIMAccept21      = "7.21" // ../rfc/7372:148
	SePol7NoDKIMAuthorMatch22 = "7.22" // ../rfc/7372:175
	SePol7SPFResultFail23     = "7.23" // ../rfc/7372:192
	SePol7SPFError24          = "7.24" // ../rfc/7372:204
	SePol7RevDNSFail25        = "7.25" // ../rfc/7372:233
	SePol7MultiAuthFails26    = "7.26" // ../rfc/7372:246
	SePol7SenderHasNullMX27   = "7.27" // ../rfc/7505:246
	SePol7ARCFail29           = "7.29" // ../rfc/8617:1438
	SePol7MissingReqTLS30     = "7.30" // ../rfc/8689:448
)

Short enhanced reply codes, without leading number and first dot.

See https://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes.xhtml

View Source
var ErrBadAddress = errors.New("invalid email address")
View Source
var ErrBadLocalpart = errors.New("invalid localpart")
View Source
var ErrCRLF = errors.New("invalid bare carriage return or newline")
View Source
var Pedantic bool

Pedantic enables stricter parsing.

Functions

func AddressLiteral

func AddressLiteral(ip net.IP) string

AddressLiteral returns an IPv4 or IPv6 address literal for use in SMTP.

func DataWrite

func DataWrite(w io.Writer, r io.Reader) error

DataWrite reads data (a mail message) from r, and writes it to smtp connection w with dot stuffing, as required by the SMTP data command.

Messages with bare carriage returns or bare newlines result in an error.

Types

type Address

type Address struct {
	Localpart Localpart
	Domain    dns.Domain // todo: shouldn't we accept an ip address here too? and merge this type into smtp.Path.
}

Address is a parsed email address.

func NewAddress

func NewAddress(localpart Localpart, domain dns.Domain) Address

NewAddress returns an address.

func ParseAddress

func ParseAddress(s string) (address Address, err error)

ParseAddress parses an email address. UTF-8 is allowed. Returns ErrBadAddress for invalid addresses.

func ParseNetMailAddress added in v0.0.12

func ParseNetMailAddress(a string) (address Address, err error)

ParseNetMailAddress parses a not-quite-valid address as found in net/mail.Address.Address.

net/mail does parse quoted addresses properly, but stores the localpart unquoted. So an address `" "@example.com` would be stored as ` @example.com`, which we would fail to parse without special attention.

func (Address) IsZero

func (a Address) IsZero() bool

func (Address) LogString added in v0.0.3

func (a Address) LogString() string

LogString returns the address with with utf-8 in localpart and/or domain. In case of an IDNA domain and/or quotable characters in the localpart, an address with quoted/escaped localpart and ASCII domain is also returned.

func (Address) Pack

func (a Address) Pack(smtputf8 bool) string

Pack returns the address in string form. If smtputf8 is true, the domain is formatted with non-ASCII characters. If localpart has non-ASCII characters, they are returned regardless of smtputf8.

func (Address) Path added in v0.0.8

func (a Address) Path() Path

func (Address) String

func (a Address) String() string

String returns the address in string form with non-ASCII characters.

type DataReader

type DataReader struct {
	// contains filtered or unexported fields
}

DataReader is an io.Reader that reads data from an SMTP DATA command, doing dot unstuffing and returning io.EOF when a bare dot is received. Use NewDataReader.

Bare carriage returns, and the sequences "[^\r]\n." and "\n.\n" result in an error.

func NewDataReader

func NewDataReader(r *bufio.Reader) *DataReader

NewDataReader returns an initialized DataReader.

func (*DataReader) Read

func (r *DataReader) Read(p []byte) (int, error)

Read implements io.Reader.

type Ehlo

type Ehlo struct {
	Name   dns.IPDomain // Name from EHLO/HELO line. Can be an IP or host name.
	ConnIP net.IP       // Address of connection.
}

Ehlo is the remote identification of an incoming SMTP connection.

func (Ehlo) IsZero

func (e Ehlo) IsZero() bool

type Localpart

type Localpart string

Localpart is a decoded local part of an email address, before the "@". For quoted strings, values do not hold the double quote or escaping backslashes. An empty string can be a valid localpart. Localparts are in Unicode NFC.

func ParseLocalpart

func ParseLocalpart(s string) (localpart Localpart, err error)

ParseLocalpart parses the local part. UTF-8 is allowed. Returns ErrBadAddress for invalid addresses.

func (Localpart) DSNString

func (lp Localpart) DSNString(utf8 bool) string

DSNString returns the localpart as string for use in a DSN. utf8 indicates if the remote MTA supports utf8 messaging. If not, the 7bit DSN encoding for "utf-8-addr-xtext" from RFC 6533 is used.

func (Localpart) IsInternational

func (lp Localpart) IsInternational() bool

IsInternational returns if this is an internationalized local part, i.e. has non-ASCII characters.

func (Localpart) LogString added in v0.0.3

func (lp Localpart) LogString() string

LogString returns the localpart as string for use in smtp, and an escaped representation if it has non-ascii characters.

func (Localpart) String

func (lp Localpart) String() string

String returns a packed representation of an address, with proper escaping/quoting, for use in SMTP.

type Path

type Path struct {
	Localpart Localpart
	IPDomain  dns.IPDomain
}

Path is an SMTP forward/reverse path, as used in MAIL FROM and RCPT TO commands.

func (Path) ASCIIExtra

func (p Path) ASCIIExtra(utf8 bool) string

ASCIIExtra returns an ascii-only path if utf8 is true and the ipdomain is a unicode domain. Otherwise returns an empty string.

For use in comments in message headers added during SMTP.

func (Path) DSNString

func (p Path) DSNString(utf8 bool) string

DSNString returns a string representation as used with DSN with/without UTF-8 support.

If utf8 is false, the domain is represented as US-ASCII (IDNA), and the localpart is encoded with in 7bit according to RFC 6533.

func (Path) Equal

func (p Path) Equal(o Path) bool

func (Path) IsZero

func (p Path) IsZero() bool

func (Path) LogString added in v0.0.3

func (p Path) LogString() string

LogString returns both the ASCII-only and optional UTF-8 representation.

func (Path) String

func (p Path) String() string

String returns a string representation with ASCII-only domain name.

func (Path) XString

func (p Path) XString(utf8 bool) string

XString is like String, but returns unicode UTF-8 domain names if utf8 is true.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL