### SMTPSender Examples Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/sender.md Demonstrates creating an SMTPSender with and without authentication. ```go // Without authentication sender := enmime.NewSMTP("localhost:25", nil) // With authentication auth := smtp.PlainAuth("", "user@example.com", "password", "mail.example.com") sender := enmime.NewSMTP("mail.example.com:587", auth) ``` -------------------------------- ### PartMatcher Usage Example Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/types.md Demonstrates how to use a PartMatcher with BreadthMatchAll to find all plain text parts. ```go matcher := func(p *Part) bool { return p.ContentType == "text/plain" } attachments := root.BreadthMatchAll(matcher) ``` -------------------------------- ### Example: Convert Part Tree to Envelope Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/envelope.md This example demonstrates how to read MIME parts from a reader and then convert the resulting Part tree into an Envelope using EnvelopeFromPart. Error handling is omitted for brevity. ```go parts, _ := enmime.ReadParts(reader) env, err := enmime.EnvelopeFromPart(parts) ``` -------------------------------- ### Import enmime Package Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Import the enmime package to start using its functionalities. ```go import "github.com/jhillyerd/enmime/v2" ``` -------------------------------- ### Simple Parsing Example Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/MANIFEST.txt Demonstrates basic message parsing using ReadEnvelope and accessing the plain text content. ```go env, err := enmime.ReadEnvelope(reader) fmt.Println(env.Text) ``` -------------------------------- ### Parse and Forward Email Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md This example demonstrates how to read an email from a file, modify its headers, and then forward it using an SMTP client. Ensure you have an 'email.eml' file and an SMTP server running on localhost:25. ```Go package main import ( "bytes" "log" "net/smtp" "os" "github.com/jhillyerd/enmime/v2" ) func main() { // Read email file, _ := os.Open("email.eml") env, _ := enmime.ReadEnvelope(file) // Modify env.SetHeader("X-Forwarded-For", []string{"user@example.com"}) // Re-send sender := enmime.NewSMTP("localhost:25", nil) var buf bytes.Buffer env.Root.Encode(&buf) newFrom := "forwarder@example.com" newRecipients := []string{"recipient@example.com"} err := sender.Send(newFrom, newRecipients, buf.Bytes()) if err != nil { log.Fatal(err) } } ``` -------------------------------- ### Create a new MailBuilder Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Use the Builder function to get an initialized MailBuilder struct. This is the starting point for constructing a MIME message. ```go builder := enmime.Builder() ``` -------------------------------- ### Example Usage of ReadEnvelope Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/envelope.md Demonstrates how to read an email from a file, parse it into an Envelope, and access its plain text and attachment count. Ensure the email file exists at the specified path. ```go file, _ := os.Open("email.eml") defer file.Close() env, err := enmime.ReadEnvelope(file) if err != nil { log.Fatal(err) } fmt.Println(env.Text) fmt.Println(len(env.Attachments)) ``` -------------------------------- ### Configure Custom Email Parser Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/INDEX.md Create a custom parser instance, for example, to skip malformed parts during parsing. ```go parser := enmime.NewParser( enmime.SkipMalformedParts(true), ) env, err := parser.ReadEnvelope(reader) ``` -------------------------------- ### Build a Complete MIME Message Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/toplevelfunctions.md Construct a full MIME message by chaining builder methods. This example demonstrates setting sender, recipients, subject, text and HTML bodies, and adding file attachments. The message is then encoded into bytes for sending. ```go message, err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). CC("", "cc@example.com"). Subject("Test Message"). Text([]byte("Plain text body")). HTML([]byte("HTML body")). AddFileAttachment("/path/to/document.pdf"). Build() if err != nil { log.Fatal(err) } // Encode to bytes for sending var buf bytes.Buffer message.Encode(&buf) fmt.Println(buf.String()) ``` -------------------------------- ### Create a New MailBuilder Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/toplevelfunctions.md Use the Builder() function to get an empty MailBuilder struct. This is the starting point for constructing MIME messages using a fluent interface. ```go func Builder() MailBuilder ``` -------------------------------- ### SMTPSender Send Method Example Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/sender.md Sends an email using the SMTPSender. Handles potential errors during transmission. ```go sender := enmime.NewSMTP("mail.example.com:25", nil) err := sender.Send( "bounce@example.com", []string{"recipient@example.com"}, messageBytes, ) if err != nil { log.Printf("Failed to send email: %v", err) } ``` -------------------------------- ### Using SimpleErrorCollector with ReadHeader Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/header.md Example demonstrating how to instantiate and use a SimpleErrorCollector with the ReadHeader function to capture parsing issues. ```go // Use with ReadHeader collector := &SimpleErrorCollector{} header, err := enmime.ReadHeader(reader, collector) for _, w := range collector.Warnings { fmt.Printf("Warning: %s\n", w) } ``` -------------------------------- ### Match Any Image Content Type Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use this matcher to identify any email part where the Content-Type starts with 'image/'. ```go func(p *Part) bool { return strings.HasPrefix(p.ContentType, "image/") } ``` -------------------------------- ### Match Multipart Content Type Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use this matcher to identify any email part where the Content-Type starts with 'multipart/'. ```go func(p *Part) bool { return strings.HasPrefix(p.ContentType, "multipart/") } ``` -------------------------------- ### Match Any Text Content Type Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use this matcher to identify any email part where the Content-Type starts with 'text/'. ```go func(p *Part) bool { return strings.HasPrefix(p.ContentType, "text/") } ``` -------------------------------- ### Error Plain Text From HTML Example Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/errors.md Illustrates a scenario where enmime generates a plain text version from HTML content when no text/plain part is available. ```Go ErrorPlainTextFromHTML ``` -------------------------------- ### Get All Header Keys Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/envelope.md Retrieves a list of all header keys present in the email message. Useful for iterating through all available headers. ```go keys := env.GetHeaderKeys() for _, key := range keys { fmt.Printf("Header: %s\n", key) } ``` -------------------------------- ### Get Raw Part Content Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/types.md Use RawContent to prevent automatic decoding of Content-Transfer-Encoding and return raw part content. The default is false. ```go func RawContent(a bool) Option ``` -------------------------------- ### Check if Header Contains Addresses Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/header.md Example demonstrating how to check if a header contains email addresses using the AddressHeaders map and parse them. ```go if enmime.AddressHeaders[strings.ToLower(headerName)] { addrs, err := enmime.ParseAddressList(headerValue) // Process addresses } ``` -------------------------------- ### Get All Header Values Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/envelope.md Retrieves all values for a given header, decoding RFC 2047 encoded words into UTF-8 strings. Ideal for headers that can contain multiple entries, like 'Received'. ```go receivedHeaders := env.GetHeaderValues("Received") ``` -------------------------------- ### Create a New Parser with Options Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/parser.md Instantiates a new Parser with custom configurations using Option functions. Default configuration is applied if no options are provided. ```go parser := enmime.NewParser( enmime.SkipMalformedParts(true), enmime.MaxStoredPartErrors(10), ) ``` -------------------------------- ### Build and Run mime-dump Source: https://github.com/jhillyerd/enmime/blob/main/cmd/mime-dump/README.md Build the mime-dump utility using 'go build' and then execute it, passing an email file as an argument to parse and display its structure. ```bash go build ``` ```bash ./mime-dump ../test-data/mail/html-mime-inline.raw ``` -------------------------------- ### Build and Send Email via SMTP Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/toplevelfunctions.md Constructs a new email with specified recipients, subject, and text content, then sends it using an SMTP client. Configure the SMTP server address and port correctly. ```Go sender := enmime.NewSMTP("localhost:25", nil) err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Hello"). Text([]byte("Test message")), Send(sender) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Available enmime builder methods Source: https://github.com/jhillyerd/enmime/wiki/Builder-Usage List of available methods for configuring email content, headers, and attachments. ```go AddAttachment(b []byte, contentType string, fileName string) AddFileAttachment(path string) AddFileInline(path string) AddInline(b []byte, contentType string, fileName string, contentID string) BCC(name, addr string) BCCAddrs(bcc []mail.Address) CC(name, addr string) CCAddrs(cc []mail.Address) Date(date time.Time) From(name, addr string) HTML(body []byte) Header(name, value string) ReplyTo(name, addr string) Subject(subject string) Text(body []byte) To(name, addr string) ToAddrs(to []mail.Address) ``` -------------------------------- ### Build Simple Email Message Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/MANIFEST.txt Shows how to construct a basic email message with sender, recipient, subject, and text body using the enmime builder. ```Go msg, err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Hello"). Text([]byte("Body")). Build() ``` -------------------------------- ### Legacy System Support Configuration Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/configuration.md Configure the parser and encoder for legacy system support. This uses a custom parser for non-standard headers and encodes with quoted-printable. ```go parser := enmime.NewParser( enmime.SetCustomParseMediaType(legacyMediaTypeParser), ) encoder := enmime.NewEncoder( enmime.ForceQuotedPrintableCte(true), ) // Uses custom parser for non-standard headers, encodes with quoted-printable ``` -------------------------------- ### Build and Send an Email Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/README.md Constructs a MIME email message using a fluent interface and sends it via SMTP. Use this for programmatically creating and dispatching emails. ```go sender := enmime.NewSMTP("localhost:25", nil) err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Hello"). Text([]byte("Test")). Send(sender) ``` -------------------------------- ### Using Header Parsing with Envelope and Part Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/header.md Demonstrates how Enmime's header parsing functions are used internally by Envelope and Part types. ```go // Envelope.GetHeader uses ParseAddressList internally toAddresses, err := env.AddressList("To") ``` ```go // Envelope.GetHeader returns RFC 2047 decoded headers subject := env.GetHeader("Subject") ``` ```go // Part headers are read using ReadHeader part.setupHeaders(reader, defaultContentType) ``` -------------------------------- ### Get MailBuilder Error Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Retrieves any stored error encountered during file attachment or inline reading. Returns nil if no error occurred. ```go func (p MailBuilder) Error() error ``` -------------------------------- ### Send Email via SMTP Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/MANIFEST.txt Demonstrates sending a constructed email message using an SMTP client. ```Go sender := enmime.NewSMTP("mail.example.com:25", auth) err := builder.Send(sender) ``` -------------------------------- ### Build Message with Attachments Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/MANIFEST.txt Illustrates adding file attachments to an email message during the build process. ```Go msg, err := enmime.Builder(). From(...).To(...).Subject(...). Text(...). AddFileAttachment("/path/file.pdf"). Build() ``` -------------------------------- ### Create New Part Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/part.md Creates a new Part object with the specified content type. Use this to initialize a new email part. ```go textPart := enmime.NewPart("text/plain") textPart.Content = []byte("Hello, world!") htmlPart := enmime.NewPart("text/html") htmlPart.Content = []byte("...") ``` -------------------------------- ### Parse an Email Message Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/README.md Reads a MIME message from a reader and extracts envelope information. Use this to quickly get the subject and text body of an email. ```go env, err := enmime.ReadEnvelope(reader) if err != nil { log.Fatal(err) } fmt.Println("Subject:", env.GetHeader("Subject")) fmt.Println("Body:", env.Text) ``` -------------------------------- ### Construct and send a message with enmime Source: https://github.com/jhillyerd/enmime/wiki/Builder-Usage Use the fluent builder to define message components and send via SMTP. ```go msg := enmime.Builder(). From("Alice", "alice@inbucket.org"). Subject("Greetings!"). Text([]byte("Hi Bob!")). To("Bob", "bob@inbucket.org") err := msg.Send(smtpHost, smtpAuth) ``` -------------------------------- ### Custom Email Parsing Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/MANIFEST.txt Demonstrates how to create a custom parser with specific options like skipping malformed parts and disabling text conversion. ```Go parser := enmime.NewParser( enmime.SkipMalformedParts(true), enmime.DisableTextConversion(true), ) env, err := parser.ReadEnvelope(reader) ``` -------------------------------- ### Find Inline Images in Email Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use BreadthMatchAll to find parts with Disposition 'inline' and ContentType starting with 'image/'. This helps in identifying and processing images embedded within the email body. ```go env, _ := enmime.ReadEnvelope(reader) images := env.Root.BreadthMatchAll(func(p *Part) bool { return p.Disposition == "inline" && strings.HasPrefix(p.ContentType, "image/") }) for _, img := range images { fmt.Printf("Image: %s (CID: %s)\n", img.FileName, img.ContentID) } ``` -------------------------------- ### NewParser Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Creates a new configured Parser instance with optional configuration options. ```APIDOC ## NewParser ### Description Creates a new configured Parser instance with optional configuration options. ### Function Signature `NewParser(...Option) *Parser` ### Parameters #### Query Parameters - `...Option` (type: ...Option) - Optional - Configuration options for the parser. ### Returns - `*Parser`: A pointer to the newly created Parser object. ``` -------------------------------- ### Configure and Use Custom Parser Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Create a custom enmime parser with specific configurations like skipping malformed parts, disabling text conversion, or setting a limit on stored part errors. Then use this parser to read envelopes or parts. ```go parser := enmime.NewParser( enmime.SkipMalformedParts(true), enmime.DisableTextConversion(true), enmime.MaxStoredPartErrors(10), ) env, err := parser.ReadEnvelope(reader) root, err := parser.ReadParts(reader) env, err := parser.EnvelopeFromPart(root) ``` -------------------------------- ### Get Specific Header Value Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/envelope.md Retrieves a single header's value, decoding RFC 2047 encoded words into a UTF-8 string. Use for headers expected to have one value. ```go subject := env.GetHeader("Subject") from := env.GetHeader("From") ``` -------------------------------- ### Build an Email Message Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/INDEX.md Construct a new email message with sender, recipient, subject, and body using the enmime builder. ```go msg, err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Hello"). Text([]byte("Body")). Build() ``` -------------------------------- ### Complex Matching for Email Parts Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/matching.md Combine multiple criteria to precisely select email parts. Examples include finding image attachments, text body parts, problematic parts with errors, or large attachments. ```go // Image attachments imageAttachments := root.BreadthMatchAll(func(p *Part) bool { return p.Disposition == "attachment" && strings.HasPrefix(p.ContentType, "image/") }) // Text body parts (not attachments) bodyText := root.BreadthMatchAll(func(p *Part) bool { return (p.ContentType == "text/plain" || p.ContentType == "text/html") && p.Disposition != "attachment" }) // Unread parts (those with errors) problematicParts := root.BreadthMatchAll(func(p *Part) bool { return len(p.Errors) > 0 }) // Large attachments largeFiles := root.BreadthMatchAll(func(p *Part) bool { return p.Disposition == "attachment" && len(p.Content) > 1_000_000 }) ``` -------------------------------- ### Set From Address Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Sets the From header with a display name and email address. Use this when initializing or updating the sender's information. ```go builder = builder.From("John Doe", "john@example.com") ``` -------------------------------- ### enmime Type Aliases for Headers Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Commonly used string constants for address headers. ```go // Address headers map envelope.AddressHeaders["to"] envelope.AddressHeaders["cc"] envelope.AddressHeaders["bcc"] envelope.AddressHeaders["from"] envelope.AddressHeaders["reply-to"] // ... and others ``` -------------------------------- ### Create New SMTPSender Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/sender.md Constructs a new SMTPSender. Authentication is optional. ```go func NewSMTP(addr string, auth smtp.Auth) *SMTPSender ``` -------------------------------- ### Organizing Email Parts with Envelope Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/matching.md Demonstrates how the Envelope type uses matching functions to automatically organize email parts such as attachments, inlines, and other multipart content. These are populated using BreadthMatchAll with specific matchers. ```Go env, _ := enmime.ReadEnvelope(reader) // These are populated using BreadthMatchAll with specific matchers fmt.Println("Attachments:", len(env.Attachments)) // p.Disposition == "attachment" fmt.Println("Inlines:", len(env.Inlines)) // p.Disposition == "inline" fmt.Println("OtherParts:", len(env.OtherParts)) // Other multipart content ``` -------------------------------- ### Configuration Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/MANIFEST.txt Options for configuring the parser and encoder. ```APIDOC ## NewParser ### Description Creates a new Parser instance with optional configuration options. ### Method Go Function ### Signature `func NewParser(options ...ParserOption) *Parser` ### Parameters - **options** (...ParserOption) - A variadic list of ParserOption functions to configure the parser. ### Example Options - `SkipMalformedParts` - `MultipartWOBoundaryAsSinglePart` - `MaxStoredPartErrors` - `RawContent` ``` ```APIDOC ## NewEncoder ### Description Creates a new Encoder instance with optional configuration options. ### Method Go Function ### Signature `func NewEncoder(options ...EncoderOption) *Encoder` ### Parameters - **options** (...EncoderOption) - A variadic list of EncoderOption functions to configure the encoder. ### Example Options - `MaxLineLength` - `WriteBoundary` ``` -------------------------------- ### Configure Custom MIME Parser Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/README.md Creates a custom MIME parser with specific configurations, such as skipping malformed parts or disabling text conversion. Use this to tailor parsing behavior. ```go parser := enmime.NewParser( enmime.SkipMalformedParts(true), enmime.DisableTextConversion(true), ) env, err := parser.ReadEnvelope(reader) ``` -------------------------------- ### From Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Sets the From header with a display name and email address for the sender. ```APIDOC ## From ### Description Sets the From header with a name and email address. ### Method MailBuilder.From ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **name** (string) - Optional - Display name for the sender - **addr** (string) - Required - Email address of the sender ### Returns MailBuilder — copy with From header set ### Example ```go builder = builder.From("John Doe", "john@example.com") ``` ``` -------------------------------- ### Build Basic Email Message Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Construct a basic MIME message using the enmime.Builder. Specify sender, recipient, subject, and plain text content. ```go msg, err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Hello"). Text([]byte("Plain text body")), Build() // Returns: *Part (root of MIME tree) ``` -------------------------------- ### Match Email Parts by Filename Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/matching.md Select parts by their FileName attribute. Supports exact matches, suffix checks, or simply checking for the presence of a filename. ```go // Parts with specific filename document := root.BreadthMatchFirst(func(p *Part) bool { return p.FileName == "report.pdf" }) // Parts matching filename pattern pdfFiles := root.BreadthMatchAll(func(p *Part) bool { return strings.HasSuffix(p.FileName, ".pdf") }) // Parts with any filename withFilename := root.BreadthMatchAll(func(p *Part) bool { return p.FileName != "" }) ``` -------------------------------- ### Send Email with MailBuilder and SMTPSender Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/sender.md Builds and sends an email using MailBuilder and an SMTPSender. ```go // Build and send a message sender := enmime.NewSMTP("localhost:25", nil) err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Hello"). Text([]byte("This is a test email")), Send(sender) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Standard Header Parameters Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/header.md Constants for standard MIME header parameter names extracted from headers like Content-Type. ```go const ( hpBoundary = "boundary" hpCharset = "charset" hpFile = "file" hpFilename = "filename" hpName = "name" hpModDate = "modification-date" ) ``` -------------------------------- ### enmime Type Aliases for Dispositions Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Commonly used string constants for content disposition types. ```go // Dispositions envelope.cdAttachment // "attachment" envelope.cdInline // "inline" ``` -------------------------------- ### Build Email Message with Attachments Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Construct a MIME message with file attachments. Supports adding attachments by byte slice or by file path. ```go msg, err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Report"). Text([]byte("See attached")), AddAttachment(pdfBytes, "application/pdf", "report.pdf"). AddFileAttachment("/path/to/image.png"), Build() ``` -------------------------------- ### Search Message Parts by Content Type Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/MANIFEST.txt Shows how to find specific parts within an email message, such as all image parts, using a breadth-first search. ```Go images := root.BreadthMatchAll(func(p *Part) bool { return strings.HasPrefix(p.ContentType, "image/") }) ``` -------------------------------- ### Handling Non-indented Header Continuations Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/header.md Shows how Enmime repairs header values that continue on a new line without indentation. ```go Subject: This is a long header value without indentation ^ non-indented continuation is repaired with warning ``` -------------------------------- ### Preserve Original Format Configuration Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/README.md Configure the enmime parser to preserve the raw content, disable text conversion, and disable character detection. ```go parser := enmime.NewParser( enmime.RawContent(true), enmime.DisableTextConversion(true), enmime.DisableCharacterDetection(true), ) ``` -------------------------------- ### Handling Space Before Colon in Headers Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/header.md Demonstrates how Enmime repairs headers with a space before the colon separator. ```go X-Custom : value ^ space before colon is repaired ``` -------------------------------- ### Implement Custom Sender Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/sender.md Provides a template for creating a custom Sender implementation for non-SMTP transports. ```go type CustomSender struct { // Your fields } func (c *CustomSender) Send(reversePath string, recipients []string, msg []byte) error { // Your implementation return nil } // Use it with MailBuilder builder := enmime.Builder() // ... configure builder ... customSender := &CustomSender{} err := builder.Send(customSender) ``` -------------------------------- ### Build Email Message for Testing Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use the enmime.Builder to construct an email message programmatically. Setting RandSeed ensures reproducible boundary generation for consistent testing. ```go // Reproducible boundary generation msg, _ := enmime.Builder(). RandSeed(12345). From("test@example.com", "test@example.com"). To("", "recipient@example.com"). Subject("Test"). Text([]byte("Test body")). Build() // Encode and verify var buf bytes.Buffer msg.Encode(&buf) output := buf.String() // Consistent output due to RandSeed ``` -------------------------------- ### Configure Parser Minimum Charset Detection Runes Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/configuration.md Sets the minimum number of runes before charset detection is attempted. Adjust detection sensitivity; higher values reduce false detection on short text, lower values enable detection on brief messages. ```Go parser := enmime.NewParser( enmime.MinCharsetDetectRunes(50), // Enable detection on text > 50 runes ) ``` -------------------------------- ### Create a Lenient Custom Parser Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/toplevelfunctions.md Instantiate a custom enmime Parser with options for lenient parsing, such as skipping malformed parts and treating multipart messages without a boundary as a single part. This parser can then be used to read email envelopes. ```go // Lenient parsing parser := enmime.NewParser( enmime.SkipMalformedParts(true), enmime.MultipartWOBoundaryAsSinglePart(true), ) env, err := parser.ReadEnvelope(reader) ``` -------------------------------- ### Match Specific Content-ID Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use this matcher to identify email parts with the specific Content-ID ''. ```go func(p *Part) bool { return p.ContentID == "" } ``` -------------------------------- ### Build an Email Message Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Constructs a tree of Part structs from the configured MailBuilder. Performs basic validations and sets the Date header if not explicitly set. Requires a From address and at least one recipient. ```go root, err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Test"). Text([]byte("Hello")). Build() if err != nil { // handle error } ``` -------------------------------- ### Build Email Message with HTML Alternative Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Create a MIME message that includes both plain text and HTML versions of the body. This allows email clients to display the most appropriate format. ```go msg, err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Hello"). Text([]byte("Plain text")), HTML([]byte("...")), Build() ``` -------------------------------- ### Handling Missing Colons in Headers Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/header.md Explains that lines missing a colon separator are skipped with an error. ```go X-Malformed no colon ^ line is skipped with error ``` -------------------------------- ### Provide Custom Media Type Parser Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/types.md Use SetCustomParseMediaType to supply a custom media type parser instead of the default. The custom parser function should match the CustomParseMediaType signature. ```go func SetCustomParseMediaType(customParseMediaType CustomParseMediaType) Option ``` ```go type CustomParseMediaType func(ctype string) (mtype string, params map[string]string, invalidParams []string, err error) ``` -------------------------------- ### Convert Part Tree to Envelope (Default Parser) Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/envelope.md Use this function to convert a Part tree into an Envelope using the default parser configuration. It automatically sorts parts into categories like Text, HTML, and Attachments. Ensure the root Part is valid. ```go func EnvelopeFromPart(root *Part) (*Envelope, error) ``` -------------------------------- ### Lenient Parsing Configuration Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/README.md Configure the enmime parser for maximum recovery from malformed parts, multipart messages without boundaries, and invalid media type characters. ```go parser := enmime.NewParser( enmime.SkipMalformedParts(true), enmime.MultipartWOBoundaryAsSinglePart(true), enmime.StripMediaTypeInvalidCharacters(true), ) ``` -------------------------------- ### Build Email Message with Custom Headers Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Add custom headers to a MIME message during the building process. Use the Header method for arbitrary key-value pairs. ```go msg, err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Hello"). Header("X-Priority", "2"). Header("X-Custom", "value"). Text([]byte("Body")), Build() ``` -------------------------------- ### enmime Type Aliases for Content Types Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Commonly used string constants for MIME content types. ```go // Content types envelope.ctTextPlain // "text/plain" envelope.ctTextHTML // "text/html" envelope.ctMultipartMixed // "multipart/mixed" envelope.ctMultipartAltern // "multipart/alternative" envelope.ctMultipartRelated // "multipart/related" envelope.ctAppOctetStream // "application/octet-stream" ``` -------------------------------- ### NewParser Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/toplevelfunctions.md Creates a new Parser instance with customizable options for advanced parsing scenarios. ```APIDOC ## NewParser ### Description Creates a new Parser instance with customizable options for advanced parsing scenarios. ### Example (Lenient parsing) ```go // Lenient parsing parser := enmime.NewParser( enmime.SkipMalformedParts(true), enmime.MultipartWOBoundaryAsSinglePart(true), ) env, err := parser.ReadEnvelope(reader) ``` ### Example (Strict parsing) ```go // Strict parsing parser := enmime.NewParser( // No options: use defaults which are strict ) env, err := parser.ReadEnvelope(reader) ``` ### Example (Raw content for archival) ```go // Raw content for archival parser := enmime.NewParser( enmime.RawContent(true), ) root, err := parser.ReadParts(reader) // root.Content contains encoded bytes ``` ``` -------------------------------- ### Match Parts with Filename Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use this matcher to identify email parts that have a FileName specified. ```go func(p *Part) bool { return p.FileName != "" } ``` -------------------------------- ### Create a Custom Parser for Raw Content Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/toplevelfunctions.md Configure a custom enmime Parser to retain raw content by setting the RawContent option to true. This is useful for archival purposes. The parser can then read parts of a message, with the content stored in its encoded form. ```go // Raw content for archival parser := enmime.NewParser( enmime.RawContent(true), ) root, err := parser.ReadParts(reader) // root.Content contains encoded bytes ``` -------------------------------- ### Strict Parsing Configuration Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/configuration.md Configure the parser for strict parsing. This setting fails on any parsing error, detects charsets, and converts HTML to text. ```go parser := enmime.NewParser( enmime.SkipMalformedParts(false), enmime.DisableCharacterDetection(false), enmime.DisableTextConversion(false), ) // Fails on any parsing error, detects charsets, converts HTML to text ``` -------------------------------- ### NewPart Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/part.md Creates a new Part object with the specified content type. This is the primary constructor for creating individual MIME parts. ```APIDOC ## NewPart Constructor ### Description Creates a new Part object with the specified content type. This is the primary constructor for creating individual MIME parts. ### Signature ```go func NewPart(contentType string) *Part ``` ### Parameters #### Path Parameters - **contentType** (string) - Required - MIME content type (e.g., "text/plain") ### Returns - ***Part** - A pointer to the newly created Part object. ### Example ```go textPart := enmime.NewPart("text/plain") textPart.Content = []byte("Hello, world!") htmlPart := enmime.NewPart("text/html") htmlPart.Content = []byte("...") ``` ``` -------------------------------- ### Update Import Path Source: https://github.com/jhillyerd/enmime/wiki/Enmime-Migration-Guide Update the import statement to reflect the new package location. ```go import "github.com/jhillyerd/go.enmime" ``` ```go import "github.com/jhillyerd/enmime" ``` -------------------------------- ### Custom Sender Implementation Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/sender.md Demonstrates how to implement a custom Sender for non-SMTP transports and integrate it with MailBuilder. ```APIDOC ## Implementing Custom Senders ### Description To implement a custom Sender for non-SMTP transport: ### Example ```go type CustomSender struct { // Your fields } func (c *CustomSender) Send(reversePath string, recipients []string, msg []byte) error { // Your implementation return nil } // Use it with MailBuilder builder := enmime.Builder() // ... configure builder ... customSender := &CustomSender{} err := builder.Send(customSender) ``` ``` -------------------------------- ### Standard Header Names Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/header.md Constants for standard MIME header names used for comparison. ```go const ( hnContentDisposition = "Content-Disposition" hnContentEncoding = "Content-Transfer-Encoding" hnContentID = "Content-ID" hnContentType = "Content-Type" hnMIMEVersion = "MIME-Version" ) ``` -------------------------------- ### Match PDF Files by Suffix Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use this matcher to identify email parts whose filenames end with '.pdf'. ```go func(p *Part) bool { return strings.HasSuffix(p.FileName, ".pdf") } ``` -------------------------------- ### Custom Error Policy for Text Parts Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/errors.md Configure the parser to allow recovery from corrupt base64 encoding in text parts using `enmime.SetReadPartErrorPolicy` with `enmime.AllowCorruptTextPartErrorPolicy`. ```go // Allow recovery from corrupt base64 in text parts parser := enmime.NewParser( enmime.SetReadPartErrorPolicy( enmime.AllowCorruptTextPartErrorPolicy, ), ) env, err := parser.ReadEnvelope(reader) ``` -------------------------------- ### Check for Specific Errors After Parsing Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/errors.md After attempting to read an envelope, iterate through `env.Errors` to check for specific non-fatal parsing issues like charset conversion problems or data loss. ```go env, err := enmime.ReadEnvelope(reader) if err != nil { // Hard parsing error log.Fatal(err) } // Check for non-fatal parsing issues for _, parseErr := range env.Errors { if parseErr.Name == enmime.ErrorCharsetConversion { fmt.Printf("Charset conversion issue: %s\n", parseErr.Detail) } if parseErr.Severe { fmt.Printf("Data loss: %s\n", parseErr.Error()) } } ``` -------------------------------- ### Search Email Parts by Content Type Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/INDEX.md Find specific parts within an email, such as all image parts, using BreadthMatchAll. ```go images := root.BreadthMatchAll(func(p *Part) bool { return strings.HasPrefix(p.ContentType, "image/") }) ``` -------------------------------- ### Configure Parser to Read Raw Content Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/configuration.md When true, Content-Transfer-Encoding is not decoded; when false, automatic decoding is applied. Use to retrieve raw encoded content without automatic decoding for archival, integrity checking, or custom processing. ```Go parser := enmime.NewParser( enmime.RawContent(true), ) root, err := parser.ReadParts(reader) // root.Content contains encoded bytes, not decoded content ``` -------------------------------- ### NewSMTP Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Creates a new SMTPSender instance for sending emails via SMTP. ```APIDOC ## NewSMTP ### Description Creates a new SMTPSender instance for sending emails via SMTP. ### Function Signature `NewSMTP(string, smtp.Auth) *SMTPSender` ### Parameters #### Path Parameters - `string` (type: string) - Required - The SMTP server address. - `smtp.Auth` (type: smtp.Auth) - Required - The SMTP authentication details. ### Returns - `*SMTPSender`: A pointer to the newly created SMTPSender object. ``` -------------------------------- ### Depth-First Search for First Matching Part Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/part.md Employ DepthMatchFirst to locate the first part encountered in a depth-first search that meets the specified criteria. This is efficient for finding a single instance of a part deep within the tree structure. ```go func (p *Part) DepthMatchFirst(matcher PartMatcher) *Part ``` ```go textPart := root.DepthMatchFirst(func(p *Part) bool { return p.ContentType == "text/plain" }) ``` -------------------------------- ### Match XLSX Files by Suffix Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use this matcher to identify email parts whose filenames end with '.xlsx'. ```go func(p *Part) bool { return strings.HasSuffix(p.FileName, ".xlsx") } ``` -------------------------------- ### Content-Type Constants Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/types.md Standard MIME content types used for comparison and classification within the package. ```go const ( ctAppOctetStream = "application/octet-stream" ctMultipartAltern = "multipart/alternative" ctMultipartMixed = "multipart/mixed" ctMultipartPrefix = "multipart/" ctMultipartRelated = "multipart/related" ctTextPlain = "text/plain" ctTextHTML = "text/html" ) ``` -------------------------------- ### Read Email Envelope with Default Parser Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Read an email envelope from a reader using the default enmime parser configuration, which includes recommended settings. ```go env, err := enmime.ReadEnvelope(reader) // Uses recommended defaults ``` -------------------------------- ### Depth-First Search for All Matching Parts Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/part.md Utilize DepthMatchAll to gather all parts matching a condition through a depth-first traversal. This method is ideal for scenarios where all occurrences of a part type, regardless of their depth, need to be identified. ```go func (p *Part) DepthMatchAll(matcher PartMatcher) []*Part ``` ```go allParts := root.DepthMatchAll(func(p *Part) bool { return true // Matches all parts }) ``` -------------------------------- ### Parsing Functions Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/MANIFEST.txt Entry point functions for parsing email messages into different structures. ```APIDOC ## ReadParts ### Description Parses an email message into a tree of Part structures. ### Method Go Function ### Signature `func ReadParts(r io.Reader) (*Part, error)` ### Parameters - **r** (*io.Reader*) - The reader to parse the email from. ### Response - **(*Part, error)** - A pointer to the root Part of the message tree and an error if parsing fails. ``` ```APIDOC ## ReadEnvelope ### Description Parses an email message into an Envelope structure, which wraps the message and its parts. ### Method Go Function ### Signature `func ReadEnvelope(r io.Reader) (*Envelope, error)` ### Parameters - **r** (*io.Reader*) - The reader to parse the email from. ### Response - **(*Envelope, error)** - A pointer to the parsed Envelope and an error if parsing fails. ``` ```APIDOC ## EnvelopeFromPart ### Description Converts a Part structure into an Envelope structure. ### Method Go Function ### Signature `func EnvelopeFromPart(p *Part) (*Envelope, error)` ### Parameters - **p** (*Part*) - The Part to convert. ### Response - **(*Envelope, error)** - A pointer to the created Envelope and an error if conversion fails. ``` -------------------------------- ### Strict Parsing Configuration Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/README.md Configure the enmime parser to use default strict mode by providing no options to NewParser. ```go parser := enmime.NewParser( // No options: uses defaults (strict mode) ) ``` -------------------------------- ### Configure Parser for Multipart Without Boundary Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/configuration.md When true, multipart messages without boundary parameters are treated as single-part; when false, boundary is required. Use when broken email clients send multipart messages without boundary parameters to recover the message body. ```Go parser := enmime.NewParser( enmime.MultipartWOBoundaryAsSinglePart(true), ) ``` -------------------------------- ### NewEncoder Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Creates a new Encoder instance with optional encoder configuration options. ```APIDOC ## NewEncoder ### Description Creates a new Encoder instance with optional encoder configuration options. ### Function Signature `NewEncoder(...EncoderOption) *Encoder` ### Parameters #### Query Parameters - `...EncoderOption` (type: ...EncoderOption) - Optional - Configuration options for the encoder. ### Returns - `*Encoder`: A pointer to the newly created Encoder object. ``` -------------------------------- ### Parse MIME Message into Parts Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/toplevelfunctions.md Parses a reader into a tree of Part objects using default configuration. Useful for accessing the raw message structure and content. ```go file, _ := os.Open("email.eml") defer file.Close() root, err := enmime.ReadParts(file) if err != nil { log.Fatal(err) } // Access message structure fmt.Println("Content-Type:", root.ContentType) fmt.Println("Boundary:", root.Boundary) // Find text parts textParts := root.BreadthMatchAll(func(p *Part) bool { return p.ContentType == "text/plain" }) for _, part := range textParts { fmt.Println("Text:", string(part.Content)) } ``` -------------------------------- ### Set Minimum Runes for Character Set Detection Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/types.md Use MinCharsetDetectRunes to set the minimum length of a MIME part before character set detection is attempted. Shorter text is more likely to be incorrectly detected. The default is 100. ```go func MinCharsetDetectRunes(minCharsetDetectRunes int) Option ``` -------------------------------- ### Define Option Interface Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/types.md Defines the Option interface for configuring a Parser. Implementations encapsulate parser configuration changes. ```go type Option interface { apply(p *Parser) } ``` -------------------------------- ### Update Part Parsing Source: https://github.com/jhillyerd/enmime/wiki/Enmime-Migration-Guide Update part parsing and header access to use the new Part structure and ReadParts function. ```go var part *enmime.MIMEPart part, err = enmime.ParseMIME(reader) from := part.Header().Get("From") ``` ```go var part *enmime.Part part, err = enmime.ReadParts(reader) from := part.Header.Get("From") ``` -------------------------------- ### Manipulate Email Parts Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Create new email parts, add child parts to a parent part, and encode a part to an output writer. ```go // Create new part part := enmime.NewPart("text/plain") part.Content = []byte("Hello") part.Charset = "utf-8" // Add child parts parent := enmime.NewPart("multipart/mixed") parent.AddChild(child1) parent.AddChild(child2) // Encode to output err := part.Encode(writer) ``` -------------------------------- ### Compare MailBuilder Structs for Equality Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Compares two MailBuilder structs for equality using reflection. Primarily intended for use in unit tests. ```go func (p MailBuilder) Equals(o MailBuilder) bool ``` -------------------------------- ### Add Custom Part from File Path Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Use AddFileOtherPart to add a custom part from a file. The filename and content ID are populated from the base name of the path. Errors during file reading are stored. ```go builder = builder.AddFileOtherPart(path) ``` -------------------------------- ### Set Reply-To Addresses Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Replaces all existing Reply-To addresses with a new slice of mail.Address objects. Use this when you have a predefined list of Reply-To addresses. ```go builder = builder.ReplyToAddrs(replyTo) ``` -------------------------------- ### Build Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Constructs a tree of Part structs from the configured MailBuilder. Performs basic validations: requires From address and at least one recipient (To, CC, or BCC). Sets the Date header to the current time if not explicitly set. ```APIDOC ## Build ### Description Constructs a tree of Part structs from the configured MailBuilder. Performs basic validations: requires From address and at least one recipient (To, CC, or BCC). Sets the Date header to the current time if not explicitly set. ### Returns * `*Part` - root Part of the constructed message tree ### Throws/Rejects * `error` - From address not set * `error` - No recipients (to, cc, bcc) configured ### Example ```go root, err := enmime.Builder(). From("sender@example.com", "sender@example.com"). To("", "recipient@example.com"). Subject("Test"). Text([]byte("Hello")). Build() if err != nil { // handle error } ``` ``` -------------------------------- ### Match Plain Text Content Type Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use this matcher to identify email parts with a 'text/plain' Content-Type. ```go func(p *Part) bool { return p.ContentType == "text/plain" } ``` -------------------------------- ### Configure MailBuilder with Random Seed for Testing Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/configuration.md Use RandSeed() to set a seed for random UUID boundary string generation, ensuring reproducible output in testing. This is particularly useful when testing code that generates MIME messages. ```go builder := enmime.Builder(). RandSeed(12345). From("test@example.com", "test@example.com"). To("", "recipient@example.com"). Subject("Test") ``` -------------------------------- ### Match Specific Filename Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/QUICK-REFERENCE.md Use this matcher to identify email parts with the exact filename 'document.pdf'. ```go func(p *Part) bool { return p.FileName == "document.pdf" } ``` -------------------------------- ### Add Inline Content from Bytes Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Use AddInline to add an inline part, typically for resources referenced in HTML. Provide content bytes, content type, and optionally a filename and content ID for referencing. ```go imageData := []byte{...} builder = builder.AddInline(imageData, "image/png", "logo.png", "logo-cid") ``` -------------------------------- ### Set To Addresses Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Replaces all existing To addresses with a new slice of mail.Address objects. Use this when you have a predefined list of recipients. ```go builder = builder.ToAddrs(to) ``` -------------------------------- ### Set Read Part Error Policy Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/configuration.md Configures a callback function to handle errors encountered while reading part content. The callback determines whether to attempt recovery or propagate the error. ```go func SetReadPartErrorPolicy(f ReadPartErrorPolicy) Option ``` ```go type ReadPartErrorPolicy func(*Part, error) bool ``` ```go parser := enmime.NewParser( enmime.SetReadPartErrorPolicy( enmime.AllowCorruptTextPartErrorPolicy, ), ) // Or define a custom policy customPolicy := func(p *Part, err error) bool { // Allow recovery from specific errors if isRecoverable(err) { return true } return false } parser := enmime.NewParser( enmime.SetReadPartErrorPolicy(customPolicy), ) ``` -------------------------------- ### Set Date Header Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/api-reference/mailbuilder.md Sets the Date header for the email message. Use this when you need to specify a particular time for the Date header. ```go builder = builder.Date(time.Now()) ``` -------------------------------- ### Content-Disposition Constants Source: https://github.com/jhillyerd/enmime/blob/main/_autodocs/types.md Standard MIME content dispositions indicating how a part should be handled by the recipient. ```go const ( cdAttachment = "attachment" cdInline = "inline" ) ```