Container Service: Developing an Application - Sending Email

Container Service apps can send unauthenticated email. Send email directly to, port 25. The mail relay accepts mail unauthenticated and routes to the University mail service.

Here is an example of python code that sends mail via this relay:

from email import encoders
from email.message import EmailMessage
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
import smtplib

def send_mail(message, subject, from_address, to_address, file_name=None, attachment=None, gateway=''):

   # Create a multipart email to handle attachments
   msg = MIMEMultipart()

   if type(message) is list:
       message = ''.join(message)

   msg.attach(MIMEText(message, 'plain'))
   msg['Subject'] = subject
   msg['From'] = from_address
   msg['To'] = to_address

   if attachment is not None:
      logging.debug('Now setting up attachment.')
      part = MIMEBase('application','octet-stream')

      mail_server = smtplib.SMTP(host=gateway, port=25, timeout=90)
      logging.debug("successfully passed email message to mail relay.")
   except smtplib.SMTPRecipientsRefused:
      logging.error('The following message has invalid recipients:')

Container Service apps also have access to the authenticated mail relay at  See the ITS documentation for authenticating to, and subsequently using the relay.

Last Updated: 
Wednesday, June 3, 2020