Hi everyone,
I have this error code which indicates "(Error when sending email: Error al enviar el correo: (10061, 'Connection refused')
I added the following function and script into the event 'mouseClicked' to a button component ('Prueba')
import smtplib
def send_email():
from_email = "juan_gerardo_rivera@whirlpool.com"
to_emails = ["juan_gerardo_rivera@whirlpool.com", "sergio_cruz@whirlpool.com"]
subject = "Prueba"
body = "Hola, este correo se envio desde Ignition"
msg = "Subject: %s\n\n%s" % (subject, body)
try:
print "Conectando al servidor SMTP..."
server = smtplib.SMTP('mailhost.whirlpool.com', 587)
server.starttls()
print "Iniciando sesión en el servidor SMTP... " #Logging into server
server.login(from_email, NaMia/Mantenimiento1506")
print "Enviando correo..."
server.sendmail(from_email, to_emails, msg)
server.quit()
print "Correo enviado exitosamente" #Email sent successfully
except Exception, e:
print "Error al enviar el correo:", str(e) #Error when sending email
send_email()
Btw, I just modified the password for security reasons.
This is the configuration set in the gateway.
I don't know if something is wrong with my script or the email settings
If you're trying to use a SMTP profile to send email, you need to use one of the built in scripting functions like system.net.sendEmail() One advantage of using the built in function (other than simplicity) is you get a lot better logging available to you.
1 Like
Thank you for the advice, Kathy,
I have changed the script so it is more based using the system.net.sendEmail()
smtpProfile = "Whirlpool Mailhost" # Usa el nombre del perfil creado en el Gateway
fromAddr = "juan_gerardo_rivera@whirlpool.com"
to = ["juan_gerardo_rivera@whirlpool.com", "sergio_cruz@whirlpool.com"]
subject = "Prueba desde Ignition"
body = "Hola, este correo se envió desde Ignition usando un perfil SMTP configurado en el Gateway."
try:
system.net.sendEmail(smtpProfile=smtpProfile, fromAddr=fromAddr, subject=subject, body=body, to=to)
print "Correo enviado exitosamente"
except Exception, e:
print "Error al enviar el correo:", str(e)
Now the error shown by Ignition is the following one: Traceback (most recent call last):
File "event:mouseClicked", line 8, in
File "event:mouseClicked", line 8, in
I have these setting in the gateway's email configuration and I attached a screenshot of my script within the mouseClicked()
I don't know if it is something related to my script or a restriction from IT
Best regards.
Did you test your email profile configuration?
1 Like
Hey, I realized the port number was different, I checked with our IT area which port was available and the told me to use port "25" because it is what Ignition is connected directly and it is working now!
Thank you for help and regards!
1 Like
Set your "from" email address to something that will help trace it to its source if it starts spamming or creating problems. Something like scriptName.projectName@gatewayName.yourCompany.com
will be a huge help to IT, etc.
I'd also remove the hard-coded "Whirlpool Mailhost" from your script. If you ever change your email provider you would have to rename everything. Instead give it a generic name, "SMTP for Ignition" or similar. Then you can edit the SMTP profile to point to your new service provider but you won't have to find and edit your scripts.
2 Likes