We have a .Net app that sends emails in the background from D3. If you need to send emails more interactively, have you consider using Python? Here is a sample code.
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(sender_email, sender_password, receiver_email, subject, body):
# Outlook SMTP server address and port
smtp_server = 'smtp-mail.outlook.com'
smtp_port = 587 # Port for STARTTLS
# Create a MIMEText object to represent the email
message = MIMEMultipart()
message['From'] = sender_email
message['To'] = receiver_email
message['Subject'] = subject
message.attach(MIMEText(body, 'plain'))
try:
# Establish a secure session with Outlook's SMTP server
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls() # Enable encryption for the connection
# Login using your Outlook email address and password
server.login(sender_email, sender_password)
# Send the email
server.sendmail(sender_email, receiver_email, message.as_string())
print('Email sent successfully!')
except Exception as e:
print(f'Failed to send email. Error: {str(e)}')
finally:
server.quit() # Terminate the SMTP session
# Example usage:
if __name__ == "__main__":
sender_email = 'your_outlook_email@example.com'
sender_password = 'your_outlook_password'
receiver_email = 'recipient@example.com'
subject = 'Test Email from Python'
body = 'Hello, this is a test email sent from Python using Outlook SMTP.'
send_email(sender_email, sender_password, receiver_email, subject, body)