2

I have to send an email from python function to multiple users with dynamic content.

I have given email details in gramex.yaml as below

email:
  barcode-mail-service:
    type: gmail
    email: gramex.guide@gmail.com
    password: alphaBetaGamma

In my python function I have implemented mail functionality as below:

def email_users(_pending_users, approval):
    mailer = service.email['barcode-mail-service']
    content = []
    if approval == 'Approved':
        content = [f"Hi {obj['user']},\n\n \
                    Welcome to the Service online portal!"
                    for obj in 
                    _pending_users.to_dict('r')
                  ]
    else:
        content = [f"Hi {obj['user']},\n\n \
                   Your request has been rejected by the approver!"
                   for obj in _pending_users.to_dict('r')
                  ]
    to_list = _pending_users['email'].tolist() #gets list of all email ids
    for index in range(len(to_list)): #loops over each mail id and sends the email
        mailer.mail(
            to=to_list[index],
            subject=f'Barcode User Access {approval}',
            html=content[index]
        )

When I execute the above function I get the following error:

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

How can I fix this?

1 Answers1

1

This seems to be a Firewall issue. SMTP internally uses port 25 for sending email. Enable (Allow) port 25 on your system and try if that works. You would need to enable this port on the server as well during deployment.

Note: Check which port is being used for sending the email by your Email Exchange

You can check this link to enable on Windows OS

Vinay Ranjan
  • 294
  • 3
  • 14
  • I'm guessing they are not actually trying to connect to port 25 at all, but I am not familiar with Gramex. The post should probably include a traceback and any relevant configuration file(s) to help us see where they are trying to connect. – tripleee Jun 03 '21 at 12:37
  • @tripleee - Gramex is a Low Code Platform used for building Data Apps. Ref (https://learn.gramener.com/guide/). This problem is regarding the email service consumption (https://learn.gramener.com/guide/email/#send-email) – Vinay Ranjan Jun 03 '21 at 13:05
  • Right, so the definition of `barcode-mail-service` should probably be specifying port 587 if it's a Gmail service; but we can't tell from the information in the question. – tripleee Jun 03 '21 at 14:14
  • Right if the relay is done using SMTPS. Totally agreed @tripleee – Vinay Ranjan Jun 03 '21 at 15:03