Skip to main content

One post tagged with "SMTP"

View All Tags

OCI Email Delivery vs. AWS SES Deep Dive on OCI Email Setup

· 4 min read

Oracle Cloud Infrastructure (OCI) Email Delivery is an email sending service and SMTP relay that provides a fast, reliable managed solution for sending both bulk and transactional emails. It is an excellent choice for applications requiring email communications such as:

  • Receipts and invoices
  • Fraud detection alerts
  • Multi-factor authentication codes
  • Password reset emails

If you're currently using Amazon SES or SendGrid, OCI Email Delivery provides similar capabilities with cost-effective pricing and scalability.

Prerequisites

To use OCI Email Delivery, ensure you have:

  1. An OCI account - If you don't have one, sign up for a free trial with $300 in credits.
  2. Proper permissions - Your user should be assigned to a group with email-family management permissions.
  3. A DNS domain - Required to publish DKIM and SPF records for better email authentication.

Setting Up OCI Email Delivery

1. Generate SMTP Credentials

SMTP credentials are required to send emails via OCI Email Delivery. Follow these steps:

  1. Log into the Oracle Cloud Console.
  2. Navigate to User Settings.
  3. Scroll down to SMTP Credentials and generate new credentials.
  4. Copy and store the username and password (as they won't be visible again).

2. Create Your Email Domain

To authenticate your emails, set up an email domain:

  1. In the Oracle Cloud Console, go to Developer Services > Email Delivery.
  2. Click Email Domains and create a domain.
  3. If setting up DKIM and SPF, choose a DNS domain that you own.

3. Set Up DKIM Authentication

DomainKeys Identified Mail (DKIM) allows email receivers (e.g., Gmail, Microsoft) to verify the authenticity of your email domain.

  1. Navigate to Email Domains > DKIM and create a DKIM key.
  2. Generate a DKIM record and add a CNAME record to your DNS provider.
  3. Once verified, your DKIM status changes to Active.

DKIM Configuration in OCI

4. Create an Approved Sender

All "From" email addresses must be registered as approved senders:

  1. In the Oracle Cloud Console, go to Email Delivery.
  2. Under DKIM, find Approved Senders and create one.

5. Configure SPF Records

Sender Policy Framework (SPF) prevents email spoofing by allowing only authorized servers to send emails from your domain.

  1. Navigate to your approved sender domain.
  2. Copy the SPF TXT record values and add them to your DNS settings.
  3. Once verified, DKIM and SPF authentication will be enabled.

SPF Configuration in OCI

6. Configuring SMTP Connection

To send emails, configure your SMTP connection:

  • Public endpoint: The SMTP server to connect to.
  • SMTP ports: Use 587 for TLS encryption (recommended).
  • Security: TLS encryption is required for sending emails securely.

7. Sending an Email with Python

Now that everything is set up, let's send an email using Python and the smtplib library:

import smtplib 
import email.utils
from email.message import EmailMessage
import ssl

SENDER = 'support@exampleplus.com'
SENDERNAME = 'Support Team'
RECIPIENT = 'Recipient Email Address'
USERNAME_SMTP = 'Provide your user SMTP'
HOST = "smtp.us-ashburn-1.oraclecloud.com"
PORT = 587
SUBJECT = 'Email Delivery Test (Python smtplib)'
BODY_TEXT = (
"This email was sent through the Email Delivery SMTP "
"Interface using the Python smtplib package."
)
password_smtp = '<Replace with Password>'

msg = EmailMessage()
msg['Subject'] = SUBJECT
msg['From'] = email.utils.formataddr((SENDERNAME, SENDER))
msg['To'] = RECIPIENT
msg.add_alternative(BODY_TEXT, subtype='text')

try:
server = smtplib.SMTP(HOST, PORT)
server.ehlo()
server.starttls(context=ssl.create_default_context())
server.ehlo()
server.login(USERNAME_SMTP, password_smtp)
server.sendmail(SENDER, RECIPIENT, msg.as_string())
server.close()
except Exception as e:
print(f"Error: {e}")
else:
print("Email successfully sent!")

8. Run the script with:

python3 ociemail.py

And you should see the message "Email successfully sent!".

Monitoring and Best Practices

  1. Suppression List
    OCI Email Delivery maintains a suppression list to prevent sending emails to addresses with permanent failures.

  2. Volume Testing
    To test email sending at scale, use:

    • 'discard.oracle.com': A special domain that accepts emails but does not deliver them.
    • Non-existent domains: Helps test bounce processing.

Conclusion

OCI Email Delivery provides a robust, scalable solution for sending transactional and bulk emails. We covered setting up email authentication, configuring SMTP, and sending a test email using Python. By following best practices and monitoring email performance, you can ensure reliable email delivery for your applications.

Call to Action

Choosing the right platform depends on your organizations needs. For more insights, subscribe to our newsletter for insights on cloud computing, tips, and the latest trends in technology. or follow our video series on cloud comparisons.

Interested in having your organization setup on cloud? If yes, please contact us and we'll be more than glad to help you embark on cloud journey.

Interested in getting a domain and business email? Checkout: Domain Registration and Business Email