def send_email_with_attachment_internal(
    to: str, title: str, message: str, attachment_path: str, attachment: str
) -> str:
    """Send an email

    Args:
        to (str): The email of the recipient
        title (str): The title of the email
        message (str): The message content of the email

    Returns:
        str: Any error messages
    """
    email_sender = getSender()
    email_password = getPwd()

    msg = EmailMessage()
    msg["Subject"] = title
    msg["From"] = email_sender
    msg["To"] = to

    signature = os.getenv("EMAIL_SIGNATURE")
    if signature:
        message += f"\n{signature}"

    msg.set_content(message)

    if attachment_path:
        ctype, encoding = mimetypes.guess_type(attachment_path)
        if ctype is None or encoding is not None:
            # No guess could be made, or the file is encoded (compressed)
            ctype = "application/octet-stream"
        maintype, subtype = ctype.split("/", 1)
        with open(attachment_path, "rb") as fp:
            msg.add_attachment(
                fp.read(), maintype=maintype, subtype=subtype, filename=attachment
            )

    draft_folder = os.getenv("EMAIL_DRAFT_MODE_WITH_FOLDER")

    if not draft_folder:
        smtp_host = os.getenv("EMAIL_SMTP_HOST")
        smtp_port = os.getenv("EMAIL_SMTP_PORT")
        # send email
        with smtplib.SMTP(smtp_host, smtp_port) as smtp:
            smtp.ehlo()
            smtp.starttls()
            smtp.login(email_sender, email_password)
            smtp.send_message(msg)
            smtp.quit()
        return f"Email was sent to {to}!"
    else:
        conn = imap_open(draft_folder, email_sender, email_password)
        conn.append(
            draft_folder,
            "",
            imaplib.Time2Internaldate(time.time()),
            str(msg).encode("UTF-8"),
        )
        return f"Email went to {draft_folder}!"
Send an email

    Args:
        to (str): The email of the recipient
        title (str): The title of the email
        message (str): The message content of the email

    Returns:
        str: Any error messages
    
src/autogpt_plugins/email/email_plugin/email_plugin.py