SMTP Integration Guide
Code examples for PHP, Python, Node.js, Go, and Ruby
Connection Settings
Standard Connection
- Host: smtp.cloudmails.eu
- Port: 587 (TLS) or 465 (SSL)
- Username: Your API key
- Password: Your secret key
- Timeout: 30 seconds
⚠️ Use TLS on Port 587
Port 587 requires TLS encryption. Never send credentials over plain text. Use STARTTLS upgrade after connecting.
PHP Integration
Using SwiftMailer (Recommended)
composer require swiftmailer/swiftmailer
$transport = (new Swift_SmtpTransport('smtp.cloudmails.eu', 587))
->setUsername('your_api_key')
->setPassword('your_secret_key')
->setEncryption('tls')
->setTimeout(30);
$mailer = new Swift_Mailer($transport);
$message = (new Swift_Message('Subject Line'))
->setFrom(['noreply@yourdomain.com' => 'Your Brand'])
->setTo(['recipient@example.com'])
->setReplyTo(['reply@yourdomain.com'])
->setBody('Hello, this is a test email.', 'text/plain')
->setHtmlBody('<p>Hello, this is a test email.</p>');
$mailer->send($message);
Using PHPMailer
composer require phpmailer/phpmailer
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.cloudmails.eu';
$mail->SMTPAuth = true;
$mail->Username = 'your_api_key';
$mail->Password = 'your_secret_key';
$mail->SMTPSecure = 'TLS';
$mail->Port = 587;
$mail->setFrom('noreply@yourdomain.com', 'Your Brand');
$mail->addAddress('recipient@example.com');
$mail->Subject = 'Subject Line';
$mail->Body = 'Hello, this is a test email.';
$mail->send();
Python Integration
Using smtplib
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(to, subject, body):
msg = MIMEMultipart()
msg['From'] = 'noreply@yourdomain.com'
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
with smtplib.SMTP('smtp.cloudmails.eu', 587) as server:
server.starttls()
server.login('your_api_key', 'your_secret_key')
server.send_message(msg)
send_email('recipient@example.com', 'Test Subject', 'Hello!')
Using SendGrid SDK
pip install sendgrid
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
sg = SendGridAPIClient(api_key='your_secret_key')
message = Mail(
from_email='noreply@yourdomain.com',
to_emails='recipient@example.com',
subject='Test Subject',
plain_text_content='Hello!'
)
response = sg.send(message)
print(response.status_code)
Node.js Integration
Using Nodemailer (Recommended)
npm install nodemailer
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: 'smtp.cloudmails.eu',
port: 587,
secure: false, // Use TLS
auth: {
user: 'your_api_key',
pass: 'your_secret_key'
},
connectionTimeout: 30000
});
async function sendEmail(to, subject, body) {
const info = await transporter.sendMail({
from: 'noreply@yourdomain.com',
to: to,
subject: subject,
text: body
});
console.log('Message sent: %s', info.messageId);
}
sendEmail('recipient@example.com', 'Test', 'Hello!');
Go Integration
package main
import (
"crypto/tls"
"net/smtp"
"strings"
)
func sendEmail(to, subject, body string) error {
from := "noreply@yourdomain.com"
password := "your_secret_key"
host := "smtp.cloudmails.eu"
port := "587"
auth := smtp.PlainAuth("", from, password, host)
msg := "From: " + from + "\n" +
"To: " + to + "\n" +
"Subject: " + subject + "\n\n" +
body
addr := host + ":" + port
tlsConfig := &tls.Config{
ServerName: host,
}
err := smtp.SendMail(addr, auth, from, []string{to}, []byte(msg))
return err
}
Ruby Integration
gem install mail
require 'mail'
Mail.defaults do
delivery_method :smtp,
address: 'smtp.cloudmails.eu',
port: 587,
user_name: 'your_api_key',
password: 'your_secret_key',
tls: true,
timeout: 30
end
Mail.deliver do
from 'noreply@yourdomain.com'
to 'recipient@example.com'
subject 'Test Subject'
body 'Hello!'
end
Best Practices
✓ Connection Pooling
Don't create a new SMTP connection for every email. Reuse connections with connection pooling. Most libraries handle this automatically.
✓ Async Sending
Send emails asynchronously in production. Queue the email job, return immediately to the user, and process from queue in background.
✓ Error Handling
Catch SMTP errors (connection failures, auth failures, sending failures) and implement automatic retry with exponential backoff.