← All ivy-nodes
IVYXSTUDIO · IVY NODE
E

Email Provider

ivy.node.email-provider · v0.0.0

ivyx

Sends email messages using an SMTP server. This node requires an email_message object created by the email-builder node. Use this node to deliver emails after building them with email-builder. Supports SMTP authentication with STARTTLS encryption. The node handles connection management and error reporting. Typically used in automated notification or reporting workflows.

#SMTP#Email Sending#Email Message

Inputs

FieldTypeDescription
smtp_serverrequiredstringThe address of the SMTP server.
smtp_portrequirednumberThe port of the SMTP server.
adminrequiredstringThe admin email address used for authentication.
passwordrequiredstringThe password for the admin email.
email_messagerequiredobjectAn EmailMessage object containing the email details. (Node reference)
featuresobjectFeatures
labelsobjectLabels

Outputs

FieldTypeDescription
featuresobjectFeatures
labelsobjectLabels

Source

python

# Input preparation
inp = __ivy_ctx__["nodes"][__ivy_node_id__]["input"]
smtp_server = inp["smtp_server"]
smtp_port = inp["smtp_port"]
admin = inp["admin"]
password = inp["password"]
email_message = inp["email_message"]

# Compute
import smtplib
from email.message import EmailMessage

class EmailProvider:
    """
    A class to handle email sending using an SMTP server.
    """

    def __init__(self, smtp_server: str, smtp_port: int, admin: str, password: str):
        """
        Initialize the EmailProvider instance.

        :param smtp_server: The address of the SMTP server.
        :param smtp_port: The port of the SMTP server.
        :param admin: The admin email address used for authentication.
        :param password: The password for the admin email.
        """
        self.smtp_server=smtp_server
        self.smtp_port=smtp_port
        self.admin=admin
        self.password=password

    def send_email(self, email_message: EmailMessage):
        """
        Send an email using the SMTP server.

        :param email_message: An EmailMessage object containing the email details.
        """
        try:
            with smtplib.SMTP(self.smtp_server, self.smtp_port) as server:
                server.starttls()
                server.login(self.admin, self.password)
                server.send_message(email_message)
                print("Email sent successfully.")
        except Exception as e:
            print(f"Error occurred while sending email: {e}")

email_provider = EmailProvider(
    smtp_server=smtp_server,
    smtp_port=smtp_port,
    admin=admin,
    password=password
)

email_provider.send_email(email_message=email_message)

# Output collection (runner reads __ivy_ctx__)
out = __ivy_ctx__["nodes"][__ivy_node_id__]["output"]

Tests

Requires: python:3.11

  • basic-email-send

    Send email with valid SMTP credentials and email message (should succeed).

    emailsmtpsendbasic
  • error-invalid-credentials

    Invalid SMTP credentials should handle error gracefully.

    error-handlingauthentication