Describe the problem/error/question
I have a system to receive emails with IMAP. However, I need to have the ability to reply (as a thread). This is not natively supported in the SEND EMAIL node. Hence, my idea about running a python script in the CODE node.
What is the error message (if any)?
I get an error:
1 item
success
message
false[Errno 26] Operation in progress
Please share your workflow
import smtplib
from email.mime.text import MIMEText
def send_email(sender, recipient, subject, body):
try:
# Create the email message
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = recipient
# Connect to the SMTP server
smtp_server = "send.one.com"
smtp_port = 465
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
server.login("[email protected]", "passwordreplaced")
# Send the email
server.send_message(msg)
# Close the SMTP server connection
server.quit()
return [{
"success": True,
"message": "Email sent successfully."
}]
except Exception as e:
return [{
"success": False,
"message": str(e)
}]
# Check if _input.json is None
if _input.json is None:
# Set default values for input data
sender = "[email protected]"
recipient = "[email protected]"
subject = "Test Email"
body = "This is a test email from N8N."
else:
# Retrieve the input data from the Code node
sender = _input.json.get("sender", "[email protected]")
recipient = _input.json.get("recipient", "[email protected]")
subject = _input.json.get("subject", "Test Email")
body = _input.json.get("body", "This is a test email from N8N.")
# Call the send_email function and return the result
return send_email(sender, recipient, subject, body)
Does anyone have an idea of how to fix this?