- cofigure app password for gmail smtp usage in php
- popular mail apis
- what is snooze in gmail
- email authentication protocols like SPF, DKIM, and DMARC
- what is PowerMTA
- configuring and managing PowerMTA
- imap server
- how to use mutt in ubuntu for reading mail from mbox files
cofigure app password for gmail smtp usage in php
To use Gmail SMTP with PHP, you must enable 2-Step Verification in your Google Account, generate a 16-character
App Password from the Security settings, and then use that App Password in your PHP (e.g., PHPMailer) code instead of your regular Gmail password for SMTP authentication. You'll use smtp.gmail.com, port 587 with TLS/STARTTLS, and your full Gmail address as the username in your script.
Part 1: Generate the App Password (Google Account)
- Enable 2-Step Verification: Go to your Google Account settings, find the "Security" tab, and ensure 2-Step Verification is turned ON.
- Go to App Passwords: Navigate to the App Passwords page (you may need to sign in again).
- Select App/Device: In the dropdowns, select "Mail" for the app and "Other (Custom name)" for the device (e.g., "My PHP App"), then click "Generate".
- Copy Password: Google will provide a 16-character password. Copy this immediately, as you won't see it again.
Part 2: Configure Your PHP Script (PHPMailer Example)
Use the generated 16-character password in your SMTP settings.
php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php'; // If using Composer
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'your_email@gmail.com'; // Your Gmail address
// Use the 16-character App Password here, NOT your regular password
$mail->Password = 'your_16_char_app_password'; // <<< PASTE THE GENERATED PASSWORD
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption
$mail->Port = 587; // TCP port to connect to
// Recipients
$mail->setFrom('your_email@gmail.com', 'Your Name');
$mail->addAddress('recipient_email@example.com'); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Test Email from PHP';
$mail->Body = 'This is a test email sent using Gmail SMTP with an App Password.';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
Key SMTP Settings for Gmail
- Host:
smtp.gmail.com - Port:
587 - Encryption:
TLS(STARTTLS) - Username: Your full Gmail address
- Password: Your 16-character App Password
popular mail apis
Popular email APIs include SendGrid, Mailgun, Postmark, Amazon SES, and Mailtrap, each catering to different needs, from high-volume marketing (SendGrid) and complex transactional needs (Postmark, Mailgun) to budget-friendly AWS integration (Amazon SES) and development/testing (Mailtrap), with options like Brevo and MailerSend also gaining traction for flexibility and features.
Top Email API Providers
- SendGrid (by Twilio): Great for SMBs, combining marketing & transactional emails with strong documentation and features.
- Mailgun (by Sinch): Powerful, flexible API for high-volume sending, excellent for complex needs, and offers multi-language SDKs.
- Postmark (by ActiveCampaign): Focuses on speed and deliverability for critical transactional emails, with clean tools and "Message Streams".
- Amazon SES (Simple Email Service): Extremely cost-effective, integrates seamlessly with the AWS ecosystem, best for budget-conscious AWS users.
- Mailtrap: Popular for testing/staging, offering a safe environment to catch and inspect emails, with strong analytics.
- Brevo (formerly Sendinblue): Offers marketing automation alongside transactional features, with good free plan options.
- MailerSend: Known for user-friendly interface, good analytics, and solid deliverability, with generous free tier.
- SparkPost: Enterprise-focused, known for high deliverability and support for large-scale email programs.
How to Choose
- For Transactional Speed: Postmark is a top choice.
- For Marketing & Scale: SendGrid or Brevo.
- For Budget/AWS Integration: Amazon SES.
- For Development/Testing: Mailtrap.
- For High Volume & Flexibility: Mailgun.
These APIs offer robust features like webhooks, analytics, and various libraries (Node.js, Python, PHP, etc.) to integrate email into applications.
what is snooze in gmail
n Gmail, "snooze" temporarily removes an email from your inbox, hiding it until a specific date and time you choose. When the designated time arrives, the email reappears at the top of your inbox as if it were new. This feature is useful for managing tasks and clearing your inbox of emails that don't require immediate action, such as appointment reminders or flight confirmations.
- How it works: When you snooze an email, it's moved to a "Snoozed" folder. The email will reappear in your inbox at the time you set, which can be a preset option (like "tomorrow" or "next week") or a specific date and time.
- How to snooze:
- From your inbox, hover over an email and click the clock icon that appears on the right.
- Alternatively, open the email and click the snooze icon in the toolbar at the top.
- Select a time and date from the options, or choose "Pick date & time" to set a custom one.
Where to find snoozed emails: You can access all your snoozed emails by clicking "Snoozed" in the left-hand menu or by searching for "in:snoozed" in the search bar.
email authentication protocols like SPF, DKIM, and DMARC
SPF, DKIM, and DMARC are email authentication protocols that verify an email's sender to prevent spam and phishing. SPF checks if the sending server is authorized, DKIM verifies the email's integrity with a digital signature, and DMARC tells receiving servers how to handle emails that fail SPF or DKIM checks.
SPF (Sender Policy Framework)
- What it is: A DNS record that lists the IP addresses authorized to send emails for a specific domain.
- How it works: When an email arrives, the receiving server checks the sender's IP address against the SPF record in the domain's DNS to see if it's on the approved list.
- Purpose: To prevent spammers from sending emails with a forged sender address from your domain.
DKIM (DomainKeys Identified Mail)
- What it is: A cryptographic signature added to email headers.
- How it works: The sending server uses a private key to sign each outgoing email. The public key, stored in the domain's DNS, is used by the receiving server to verify the signature and confirm the message content hasn't been altered.
- Purpose: To ensure the email originated from the domain it claims to be from and that its contents have not been tampered with in transit.
DMARC (Domain-based Message Authentication, Reporting, and Conformance)
- What it is: A policy that leverages both SPF and DKIM.
- How it works: It provides instructions to the receiving server on what to do with emails that fail SPF and/or DKIM checks. It can tell servers to do nothing (
p=none), send failing emails to spam (p=quarantine), or reject them entirely (p=reject). It also sends reports back to the sender to provide visibility into email traffic and authentication results. - Purpose: To give domain owners control over how unauthenticated emails are handled and to protect their domain's reputation by preventing fraudulent emails from reaching inboxes
what is PowerMTA
PowerMTA is a high-performance Mail Transfer Agent (MTA) designed for sending large volumes of business-critical emails reliably. It is used by email service providers, large organizations, and marketing platforms to ensure high deliverability by managing processes like IP rotation, bounce handling, and real-time delivery monitoring. Its key features include a robust analytics dashboard, advanced configuration for sending policies, and the ability to handle millions of emails per hour.
Key features and functionalities
-
Engineered to handle and deliver a massive volume of emails per hour with high performance.
Includes features to improve inbox placement, such as IP rotation to distribute load across multiple IP addresses and automated IP warming to build sender reputation.
Provides a centralized dashboard for real-time delivery tracking, bounce analysis, and performance monitoring, which helps in making data-driven decisions.
Allows for granular control over sending policies, multiple domains, and other settings, with support for various security protocols like DKIM and SPF.
Designed for enterprise-grade email communication, ensuring dependable and secure delivery and offering robust security measures
configuring and managing PowerMTA
Configuring and managing PowerMTA involves installation, core configuration via the
config file, setting up DNS records, and using the PowerMTA Management Console for monitoring and optimization. Key management tasks include monitoring performance, handling deliverability, and maintaining a good sender reputation by adhering to ISP best practices. You can watch this video to learn how to install and configure PowerMTA:
1. Installation and initial setup
- Install PowerMTA: Download and install PowerMTA on your server. This will likely involve running the installer (e.g., the
pmta.msion Windows). - Copy license file: Copy your license file (e.g.,
license.dat) to the PowerMTA installation directory. - Connect to your server: Use an SSH client like PuTTY to connect to your server.
- Set up dependencies: Ensure all required software and dependencies are installed.
- Check port 25: Verify that port 25 (or your chosen port) is not blocked by your cloud provider, as this is crucial for sending emails.
2. Core configuration
- Edit the configuration file: The main configuration file is usually located at
/etc/pmta/config(or similar). You can use a text editor likeNotepadorvimto edit it. - Configure basic settings: Update the file with your server's IP addresses, domain names, and authentication methods.
- Implement sender authentication: Set up SPF, DKIM, and DMARC records in your DNS to verify your sender authenticity.
- Configure directives: Set up domain-specific configurations or use macros to simplify settings for large numbers of domains.
- Apply management principles: Follow best practices like the DRY principle ("Don't Repeat Yourself") to keep configurations clean and manageable, especially when managing multiple domains or customers, as shown in this Slideshare document and this CircleID article.
This video explains how to set up the configuration file and DNS:
3. Management and monitoring
- Restart the service: After making configuration changes, restart the PowerMTA service to apply them. The command is typically
service pmta restart. - Use the Management Console: Access the PowerMTA Management Console (PMC) by running the necessary commands to enable the console and the port (usually 1983). The console provides a web-based interface for detailed monitoring and management.
- Monitor performance: Continuously monitor your server's performance and deliverability.
- Manage reputation: Proactively manage your sending reputation by monitoring feedback and addressing issues to avoid blacklisting.
- Maintain list quality: Use email verification tools to clean your lists and avoid sending to invalid addresses
imap server
An IMAP (Internet Message Access Protocol) server stores emails on a central server, enabling seamless access and synchronization across multiple devices (phone, computer, tablet). Key points are server-based storage, real-time syncing of actions (read, delete, move), efficient partial downloads (headers first), folder management, and strong security via SSL/TLS, making it ideal for modern multi-device users, unlike older POP protocols.
Key Features
- Multi-Device Sync: All changes (read, unread, moved) are mirrored across all connected devices because mail stays on the server.
- Server-Side Storage: Emails are kept on the server, not just downloaded to one device, preserving your mailbox across platforms.
- Partial Downloads: Downloads only email headers initially, then message bodies/attachments when clicked, saving bandwidth and speeding up access.
- Folder Management: Supports creating, deleting, and syncing folders on the server.
- Simultaneous Access: Can log in from multiple devices at once without issues.
How it Works
- Uses a client/server model over TCP/IP (ports 143/993).
- Requires an internet connection to sync changes, but cached emails allow limited offline viewing.
- Supports secure connections (SSL/TLS) for encryption.
Benefits
- Flexibility: Access email from anywhere, any device.
- Consistency: A unified view of your mailbox, always up-to-date.
- Efficiency: Faster initial loading by downloading only necessary parts.
Considerations
- Server Dependency: Relies on server uptime and might use more server storage.
- Security: Needs proper network security (firewalls, encryption) to protect data on the server.
how to use mutt in ubuntu for reading mail from mbox files
To read mail from an mbox file on Ubuntu using Mutt, you can pass the file path directly to the
mutt command using the -f flag. Since Mutt natively autodetects the mbox format, you do not need to configure an email server or complex configuration files to read a local mbox archive. [1, 2]1. Install Mutt
Ensure Mutt is installed on your Ubuntu system using the Advanced Package Tool (APT): [1]
bash
sudo apt update && sudo apt install mutt
Use code with caution.
2. Open the mbox File
Launch Mutt and point it directly to your target
.mbox file: [1]bash
mutt -f /path/to/your/file.mbox
Use code with caution.
↑/↓(ork/j): Scroll through the message index list.Enter(orSpace): Open and read the highlighted email.i: Exit the email body view and return to the main index list.d: Mark an email for deletion (only applies if you didn't use the read-only flag).c: Change to a different folder or switch to another mbox file without closing Mutt.q: Quit Mutt. [1, 2, 3, 4]
4. Optional Configuration (Fixing HTML emails)
text
auto_view text/html
alternative_order text/plain text/html
Use code with caution.
Ensure your system's global mailcap file (
/etc/mailcap) has an entry handling text/html, which is standard across Ubuntu installations. [1]If you plan to use this setup frequently, let me know if you would like to automate sorting by thread, or if you need help extracting attachments from the mbox file