You can configure Titan Email in email scripts written in PHP, Python or Node.js. This is typically used to make a contact form on your website send mail through Titan. Once set up, emails sent through your script are also copied to the Sent folder in your Titan webmail.
Before you start:
- Third-party email access must be enabled for your account. See Enable Titan on other apps.
- If two-factor authentication is on, use an application password instead of your mailbox password. See Application password in Titan for third-party clients.
- If you're in the European Union region, see this article for the Titan server details.
SMTP settings
Use one of these two configurations.
Option 1: Port 465 with SSL
| SMTP host name | smtp.titan.email |
| Port | 465 |
| Encryption | SSL |
Option 2: Port 587 with STARTTLS
| SMTP host name | smtp.titan.email |
| Port | 587 |
| Encryption | STARTTLS |
Code snippets for reference
Sample scripts are provided below for PHP, Python and Node Mailer. Replace the placeholder values (your Titan email address, password and the recipient's email address) with your own before you run the script.
The sample scripts use port 587 with STARTTLS. To use port 465 with SSL instead, change the port and the encryption setting in the script.
PHP
This script uses PHPMailer. Enable the IMAP extension in your php.ini file so the script can copy the email to the Sent folder.
<?php
// Include the PHPMailer library
require 'vendor/autoload.php';
// Email configuration
$sender_email = 'Your Titan email address';
$sender_password = 'Your Titan password';
$recipient_email = 'Recipient email';
$subject = 'Testing email script';
$body = 'This is a test email sent from a PHP script.';
// SMTP (sending) server details
$smtp_server = 'smtp.titan.email';
$smtp_port = 587;
// IMAP (receiving) server details
$imap_server = 'imap.titan.email';
$imap_port = 993;
function send_email() {
global $sender_email, $sender_password, $recipient_email, $subject, $body, $smtp_server, $smtp_port, $imap_server, $imap_port;
// Create a PHPMailer object
$mail = new \PHPMailer\PHPMailer\PHPMailer();
try {
// Configure the SMTP settings
$mail->isSMTP();
$mail->Host = $smtp_server;
$mail->Port = $smtp_port;
$mail->SMTPAuth = true;
$mail->Username = $sender_email;
$mail->Password = $sender_password;
$mail->SMTPSecure = 'tls';
// Set the email content
$mail->setFrom($sender_email);
$mail->addAddress($recipient_email);
$mail->Subject = $subject;
$mail->Body = $body;
// Send the email
if ($mail->send()) {
echo 'Email sent successfully.';
} else {
echo 'Error sending email: ' . $mail->ErrorInfo;
return;
}
// Append the sent email to the IMAP server's "Sent" folder
// Enable the IMAP extension from your php.ini file
$imap_stream = imap_open("{" . $imap_server . ":" . $imap_port . "/ssl/novalidate-cert}", $sender_email, $sender_password);
if ($imap_stream) {
imap_append($imap_stream, "{" . $imap_server . ":" . $imap_port . "/ssl/novalidate-cert}Sent", $mail->getSentMIMEMessage());
echo 'Email appended to "Sent" folder.';
imap_close($imap_stream);
} else {
echo 'Error appending email to "Sent" folder.';
}
} catch (Exception $e) {
echo 'Error sending email: ' . $e->getMessage();
}
}
// Call the function to send the email and append it to the "Sent" folder
send_email();
?>Python
import smtplib
import imaplib
import time
from email.mime.text import MIMEText
from email.header import Header
# Email configuration
sender_email = 'Your Titan email address'
sender_password = 'Your Titan password'
recipient_email = 'Recipient email'
subject = 'Testing email script'
body = 'This is a test email sent from a Python script.'
# SMTP (sending) server details
smtp_server = 'smtp.titan.email'
smtp_port = 587
# IMAP (receiving) server details
imap_server = 'imap.titan.email'
imap_port = 993
def send_email():
# Create the message
message = MIMEText(body, 'plain', 'utf-8')
message['From'] = sender_email
message['To'] = recipient_email
message['Subject'] = Header(subject, 'utf-8')
try:
# Send the email
smtp_obj = smtplib.SMTP(smtp_server, smtp_port)
smtp_obj.starttls()
smtp_obj.login(sender_email, sender_password)
smtp_obj.sendmail(sender_email, recipient_email, message.as_string())
smtp_obj.quit()
print('Email sent successfully.')
# Append the sent email to the IMAP server's "Sent" folder
imap_obj = imaplib.IMAP4_SSL(imap_server, imap_port)
imap_obj.login(sender_email, sender_password)
imap_obj.append('Sent', '', imaplib.Time2Internaldate(time.time()), message.as_bytes())
imap_obj.logout()
print('Email appended to "Sent" folder.')
except smtplib.SMTPException as e:
print('Error sending email:', str(e))
except imaplib.IMAP4.error as e:
print('Error appending email to "Sent" folder:', str(e))
# Call the function to send the email and append it to the "Sent" folder
send_email()Node Mailer
const nodemailer = require('nodemailer');
const Imap = require('imap');
const { simpleParser } = require('mailparser');
// Email configuration
const senderEmail = 'Your Titan email address';
const senderPassword = 'Your Titan password';
const recipientEmail = 'Recipient email';
const subject = 'Testing email script';
const body = 'This is a test email sent from a Node.js script.';
// SMTP (sending) server details
const smtpServer = 'smtp.titan.email';
const smtpPort = 587;
// IMAP (receiving) server details
const imapServer = 'imap.titan.email';
const imapPort = 993;
async function sendEmailAndAppend() {
try {
// Create a nodemailer transporter using SMTP
const transporter = nodemailer.createTransport({
host: smtpServer,
port: smtpPort,
auth: {
user: senderEmail,
pass: senderPassword,
},
});
// Create the email options
const mailOptions = {
from: senderEmail,
to: recipientEmail,
subject: subject,
text: body,
};
// Send the email
const info = await transporter.sendMail(mailOptions);
console.log('Email sent successfully.');
console.log('Info object:', info);
// Append the sent email to the "Sent" folder using IMAP
const imap = new Imap({
user: senderEmail,
password: senderPassword,
host: imapServer,
port: imapPort,
tls: true,
});
imap.once('ready', () => {
imap.openBox('Sent', true, (err) => {
if (err) {
console.error('Error opening "Sent" folder:', err);
imap.end();
return;
}
// Create the email message as MIMEText
const emailMessage = `From: ${senderEmail}\r\nTo: ${recipientEmail}\r\nSubject: ${subject}\r\n\r\n${body}`;
// Append the sent email to the "Sent" folder
imap.append(emailMessage, { mailbox: 'Sent' }, (appendErr) => {
if (appendErr) {
console.error('Error appending email to "Sent" folder:', appendErr);
} else {
console.log('Email appended to "Sent" folder.');
}
imap.end();
});
});
});
imap.once('error', (imapErr) => {
console.error('IMAP Error:', imapErr);
});
imap.connect();
} catch (error) {
console.error('Error sending email:', error);
}
}
// Call the function to send the email and append it to the "Sent" folder
sendEmailAndAppend();Troubleshooting
If the settings above don't work from an email client or script, it's usually one of two causes.
Case 1: Titan is blocking the client IP address
If there are repeated failed sign-in attempts, Titan blocks the client IP address. Contact support with the public IP address of the machine or server your script runs from:
- Local machine: Find your public IP address at whatismyip.com.
- Web hosting: Ask your system administrator for the server's public IP address.
Case 2: A firewall is blocking the port
Your network or hosting provider may block the port at its firewall. Try a different port and encryption combination: 465 with SSL or 587 with STARTTLS.
If it still fails, run these commands and send the output to Titan support. Replace <port-no> with the port you tried.
- Local machine: Run the commands yourself.
- Web hosting: Ask your server administrator to run them.
telnet smtp.titan.email <port-no>
telnet imap.titan.email <port-no>You need to enable telnet before you can run these commands. Setup guides: