Documentation
¶
Overview ¶
Package mailify provides functionalities for handling and processing emails. This package includes features for sending, receiving, and managing email communications in a secure and efficient manner.
Index ¶
- type Client
- func (c *Client) ExtractDomainFromEmailAddress(receipientEmail string) (string, error)
- func (c *Client) FormatValidationResult(recipientEmail string, result *ValidationResult) string
- func (c *Client) GetHostname() (string, error)
- func (c *Client) GetMailServers(domain string) ([]string, error)
- func (c *Client) GetMailServersFromReceipientEmail(email string) ([]string, error)
- func (c *Client) GetSMTPServer(mailServer string) (*SMTPDetails, error)
- func (c *Client) ProcessAndValidateEmailsViaExcel(filename string, senderEmail string) error
- func (c *Client) TryConnectingSMTP(smtpDetails *SMTPDetails, recipientEmail, localName string, useTLS bool) (*ValidationResult, error)
- func (c *Client) ValidateEmail(recipientEmail string) (*ValidationResult, error)
- type SMTPDetails
- type ValidationResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
SenderEmail string
}
Client represents an email client with a sender email address.
func NewClient ¶
NewClient creates a new Client instance with the provided sender email address. It returns a pointer to the Client and an error, if any.
Parameters:
- SenderEmail: A string representing the sender's email address.
Returns:
- *Client: A pointer to the newly created Client instance.
- error: An error if there is any issue during the creation of the Client.
func (*Client) ExtractDomainFromEmailAddress ¶
ExtractDomainFromEmailAddress extracts the domain part from the given email address. It takes a recipient email as input and returns the domain as a string. If the email format is invalid, it returns an error.
Parameters:
receipientEmail (string): The email address from which to extract the domain.
Returns:
string: The domain part of the email address. error: An error if the email format is invalid.
func (*Client) FormatValidationResult ¶
func (c *Client) FormatValidationResult(recipientEmail string, result *ValidationResult) string
Helper function to format validation results FormatValidationResult formats the validation result of an email address into a human-readable string.
Parameters:
- email: The email address that was validated.
- result: A pointer to a ValidationResult struct containing the validation details.
Returns:
A formatted string summarizing the validation results, including the email address, validation status, presence of MX records, catch-all status, and any error message.
func (*Client) GetHostname ¶
getHostname gets the fully qualified domain name for HELO command GetHostname attempts to retrieve the fully qualified domain name (FQDN) of the current host. It first tries to get the hostname using os.Hostname(). If that fails, it returns a fallback hostname "verifier.local". If successful, it then attempts to resolve the IP addresses associated with the hostname using net.LookupIP(). If that fails, it returns the hostname. If successful, it performs a reverse DNS lookup on the first IPv4 address found using net.LookupAddr(). If that succeeds and returns at least one name, it returns the first name with the trailing dot removed. If all attempts fail, it returns the hostname with ".local" appended.
func (*Client) GetMailServersFromReceipientEmail ¶
GetMailServersFromReceipientEmail extracts the domain from the given email address and retrieves the mail servers associated with that domain.
Parameters:
email (string): The recipient's email address.
Returns:
[]string: A slice of mail server addresses. error: An error object if there was an issue extracting the domain or retrieving the mail servers.
func (*Client) GetSMTPServer ¶
func (c *Client) GetSMTPServer(mailServer string) (*SMTPDetails, error)
GetSMTPServer attempts to find an available SMTP server for the given mail server. It performs a DNS lookup to get all IP addresses (both IPv4 and IPv6) associated with the mail server, and then tries to connect to common SMTP ports (587, 25, 465) on each IP address.
If a connection is successfully established, it returns the SMTP server details including the server name, port, protocol, and IP address. If no available SMTP servers are found, it returns an error.
Parameters:
- mailServer: The domain name of the mail server to look up.
Returns:
- *SMTPDetails: A struct containing the details of the SMTP server if found.
- error: An error if no available SMTP servers are found or if there is a lookup failure.
func (*Client) ProcessAndValidateEmailsViaExcel ¶ added in v1.1.0
ProcessAndValidateEmails reads an Excel file, validates emails, and writes results back ProcessAndValidateEmailsViaExcel processes and validates emails from an Excel file. It reads the email addresses from the specified Excel file, validates each email, and writes the validation results back to the Excel file in a new column.
Parameters:
- filename: The path to the Excel file containing the email addresses.
- senderEmail: The email address of the sender (not used in the current implementation).
Returns:
- error: An error if any issue occurs during the process, otherwise nil.
The function performs the following steps:
- Opens the specified Excel file.
- Reads all rows from the first sheet ("Sheet1").
- Creates a map of headers from the first row.
- Adds a new column header for email validation results if it doesn't exist.
- Iterates over each row, validates the email address, and writes the validation result to the new column.
- Saves the modified Excel file with the validation results.
The function prints progress and summary information to the console.
func (*Client) TryConnectingSMTP ¶
func (c *Client) TryConnectingSMTP(smtpDetails *SMTPDetails, recipientEmail, localName string, useTLS bool) (*ValidationResult, error)
TryConnectingSMTP attempts to establish an SMTP connection and validate an email address. It performs the following steps: 1. Creates a new validation result indicating the domain has MX records. 2. Creates a new dialer with a timeout. 3. Formats the address based on IP version (IPv4 or IPv6). 4. Handles connection based on the port (SMTPS or plain/STARTTLS). 5. Creates an SMTP client. 6. Performs HELO/EHLO command. 7. Initiates STARTTLS if available and not already using TLS. 8. Sends MAIL FROM command. 9. Sends RCPT TO command. 10. Interprets the response to determine if the email address is valid.
Parameters: - smtpDetails: Details of the SMTP server (IP address, port, server name). - senderEmail: The email address of the sender. - recipientEmail: The email address of the recipient to be validated. - localName: The local name to use in the HELO/EHLO command. - useTLS: A boolean indicating whether to use TLS.
Returns: - A pointer to a ValidationResult struct containing the validation outcome. - An error if any step in the process fails.
func (*Client) ValidateEmail ¶
func (c *Client) ValidateEmail(recipientEmail string) (*ValidationResult, error)
ValidateEmail validates the recipient's email address by checking its format, verifying the existence of MX records for the domain, and attempting to connect to the mail servers using SMTP.
Parameters:
- recipientEmail: The email address of the recipient to be validated.
- senderEmail: The email address of the sender.
Returns:
- *ValidationResult: A struct containing the validation result, including whether the email is valid, if MX records were found, and any error messages.
- error: An error object if an error occurred during the validation process.
The function performs the following steps:
- Checks if the recipient email contains an "@" symbol and splits it into local and domain parts.
- Retrieves the MX records for the domain.
- Gets the local hostname for the HELO command.
- Attempts to connect to each mail server using SMTP, first without TLS and then with TLS if the initial attempt fails.
- Returns the validation result and any errors encountered during the process.
type SMTPDetails ¶
type SMTPDetails struct { // Server is the address of the SMTP server. Server string // Port is the port number on which the SMTP server is listening. Port string // Protocol is the protocol used by the SMTP server (e.g., "SMTP", "SMTPS"). Protocol string // UsedTLS indicates whether TLS is used for the connection. UsedTLS bool // IPAddress is the IP address of the SMTP server. IPAddress string }
SMTPDetails holds the details required to connect to an SMTP server.
type ValidationResult ¶
type ValidationResult struct { // IsValid indicates whether the email address is valid. IsValid bool // IsCatchAll indicates whether the domain has a catch-all address. IsCatchAll bool // HasMX indicates whether the domain has MX records. HasMX bool // ErrorMessage contains any error message encountered during validation. ErrorMessage string // SMTPDetails contains the SMTP server details used for validation. SMTPDetails *SMTPDetails }
ValidationResult represents the result of an email validation check.