SMTP Code Examples
Complete, copy-paste-ready code examples for integrating Motorical SMTP into your application.
Basic Authentication
- 🟢 Node.js
- 🐍 Python
- 🐘 PHP
- ☕ Java
- 🔷 C#
- 🐹 Go
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransporter({
host: 'mail.motorical.com',
port: 2587,
secure: false,
auth: {
user: 'your_motor_block_username',
pass: 'your_motor_block_password'
},
tls: {
rejectUnauthorized: true
}
});
async function sendEmail() {
try {
const info = await transporter.sendMail({
subject: 'Hello from Motorical SMTP!',
text: 'This is a test email sent via Motorical SMTP.',
html: '<h1>Hello!</h1><p>Sent via <strong>Motorical SMTP</strong>.</p>'
});
console.log('Email sent:', info.messageId);
} catch (error) {
console.error('Error:', error);
}
}
sendEmail();
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email():
smtp_server = "mail.motorical.com"
smtp_port = 2587
username = "your_motor_block_username"
password = "your_motor_block_password"
msg = MIMEMultipart('alternative')
msg['Subject'] = "Hello from Motorical SMTP!"
msg['From'] = f"Your Name <{username}@your-domain.com>"
text = "This is a test email sent via Motorical SMTP."
html = "<h1>Hello!</h1><p>Sent via <strong>Motorical SMTP</strong>.</p>"
msg.attach(MIMEText(text, 'plain'))
msg.attach(MIMEText(html, 'html'))
try:
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
server.login(username, password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
print("Email sent successfully!")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
send_email()
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'mail.motorical.com';
$mail->SMTPAuth = true;
$mail->Username = 'your_motor_block_username';
$mail->Password = 'your_motor_block_password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 2587;
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Subject = 'Hello from Motorical SMTP!';
$mail->Body = '<h1>Hello!</h1><p>Sent via <strong>Motorical SMTP</strong>.</p>';
$mail->AltBody = 'This is a test email sent via Motorical SMTP.';
$mail->send();
echo "Email sent successfully!\n";
} catch (Exception $e) {
echo "Error: {$mail->ErrorInfo}\n";
}
?>
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MotoricalSMTP {
public static void main(String[] args) {
String host = "mail.motorical.com";
int port = 2587;
String username = "your_motor_block_username";
String password = "your_motor_block_password";
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", String.valueOf(port));
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
Authenticator auth = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
};
try {
Session session = Session.getInstance(props, auth);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(
username + "@your-domain.com", "Your Name"));
message.setRecipients(Message.RecipientType.TO,
message.setSubject("Hello from Motorical SMTP!");
message.setContent(
"<h1>Hello!</h1><p>Sent via <strong>Motorical SMTP</strong>.</p>",
"text/html; charset=utf-8");
Transport.send(message);
System.out.println("Email sent successfully!");
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
using System.Net;
using System.Net.Mail;
string host = "mail.motorical.com";
int port = 2587;
string username = "your_motor_block_username";
string password = "your_motor_block_password";
using (SmtpClient client = new SmtpClient(host, port))
{
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(username, password);
client.Timeout = 30000;
using (MailMessage message = new MailMessage())
{
message.From = new MailAddress(
username + "@your-domain.com", "Your Name");
message.Subject = "Hello from Motorical SMTP!";
message.IsBodyHtml = true;
message.Body = "<h1>Hello!</h1><p>Sent via <strong>Motorical SMTP</strong>.</p>";
client.Send(message);
Console.WriteLine("Email sent successfully!");
}
}
package main
import (
"net/smtp"
"fmt"
)
func main() {
host := "mail.motorical.com"
port := "2587"
username := "your_motor_block_username"
password := "your_motor_block_password"
auth := smtp.PlainAuth("", username, password, host)
"From: " + username + "@your-domain.com\r\n" +
"Subject: Hello from Motorical SMTP!\r\n" +
"Content-Type: text/html\r\n\r\n" +
"<h1>Hello!</h1><p>Sent via <strong>Motorical SMTP</strong>.</p>\r\n")
err := smtp.SendMail(host+":"+port, auth,
username+"@your-domain.com", to, msg)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Email sent successfully!")
}
API Key Authentication (HTTP API)
curl -X POST "https://mail.motorical.com:2587/api/v1/send" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"from": "[email protected]",
"to": ["[email protected]"],
"subject": "Motorical API Key Test",
"text": "Sent via API key authentication!"
}'
mTLS Authentication
# Send with client certificate
curl -X POST "https://api.motorical.com/v1/send" \
--cert your_client.crt \
--key your_client.key \
-H "Content-Type: application/json" \
-d '{
"from": "[email protected]",
"to": ["[email protected]"],
"subject": "mTLS Secured Email",
"text": "Sent using mutual TLS authentication."
}'