Errno 10060 A connection attempt failed - python

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=465
EMAIL_HOST_USER = 'yogi'
EMAIL_HOST_PASSWORD = '###'
DEFAULT_EMAIL_FROM = 'yogi#gmail.com'
above are the settings for django core mail module. I am using its send_mail to send mails to users. When i try to build the program with the gmail smtp it throws the following error
'Errno 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'.
I am doing this in my company and so it has proxy settings. I have given the proxy credentials in .condarc settings file. But still the connection timeout error. Do i need to set the proxy settings somewhere else or let me know where i am going wrong. ?

As far as I know django does not detect any SMTP proxy settings from anaconda configuration files. You can overcome this by manually building a connection.
Notice that send_mail , has an option parameter for a connection. You get one by calling mail.get_connection now you need to wrap it around sockspi
see Python smtplib proxy support and Python send email behind a proxy server for further details.

Related

Unable to run a simple SMTP server

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
import smtplib
senders='jsujith1311#gmail.com'
password="ekjhgisxavzw"#Not Original Password
connection=smtplib.SMTP("smtp.gmail.com")
connection.starttls()
connection.login(user=senders,password=password)
connection.sendmail(from_addr=senders,to_addrs=senders,msg="HI")
connection.close()
Can anyone help with this
I need a simple smtp server running on my device initially, then i want to configutre it according to my needs.
You need to change your password to an app password. Follow the below link for that: https://support.google.com/mail/answer/185833?hl=en
So, the answer is to use
connection = smtplib.SMTP_SSL("smtp.gmail.com")
and we have to remove the tls connection,I don't know why.But it worked.

Django: Outlook email smtp timeout in production server

i'm trying to send a SMTP email from Django, using my credentials of Outlook. My code works in localhost, but when I upload my code to production server, it doesn't.
If I use my Gmail credential, it also works in production, but it doesn't with Outlook. So, I think Outlook is configured in a different way, but I dont know.
This is my view code:
def send_my_custom_email():
connection = mail.get_connection(
host = 'smtp-mail.outlook.com',
port = 25,
username = 'myemail#outlook.com',
password = 'mypassword' ,
)
connection.open()
email2send = mail.EmailMessage('hello', 'hello', 'myemail#outlook.com', to=['receiveremail'], connection=connection)
email2send.send()
connection.close()
I know that my configuration setting are right because it can send emails from localhost. These are my settings.py:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
I already try to check the Outlook settings, but I couldn't find anything about SMTP use.
My exact questions are:
Outlook need aditional settings in production?
The problem is in my code or in Outlook settings?
Why it works in localhost but it does not in production server?
Outlook.com only allows encrypted SMTP TLS connections on port 587. It does not even listen on port 25, that is why you get a timeout.

pyxmpp2 connect to openfire cannot resolve NXDOMAIN

I installed pyxmpp2 https://github.com/Jajcus/pyxmpp2to my Ubuntu machine. I also installed Openfire 3.8.1 to it. I would like to use pyxmpp2 to connect to my Openfire server within the same machine.
In the Server -> Server Manager-> Server Information in my Openfire control panel, the Server Name showed in Server Properties in the panel was mymachine and the Host Name showed in the Environment section was MyMachine.
I tried the following code:
import logging
from pyxmpp2.jid import JID
from pyxmpp2.client import Client
logging.basicConfig()
client = Client(JID("admin#mymachine"),[])
client.connect()
and got the following message:
WARNING:pyxmpp2.resolver:Could not resolve '_xmpp-client._tcp.mymachine': NXDOMAIN
Did I miss configuring something?
It looks like there are no DNS SRV records for your domain and pyxmpp2 is therefore unable to resolve them. Have a look at http://wiki.xmpp.org/web/SRV_Records on how to create them.
Basically a DNS SRV record has the form
_service._proto.name TTL class SRV priority weight port target
which could look like this example
_xmpp-client._tcp.example.net. 86400 IN SRV 5 0 5222 example.net.
Maybe pyxmpp2 also provides a way to directly specify the host used for the XMPP service. This would avoid the DNS SRV lookup.
It may be using ipv6, you can force ipv4 using u"ipv4": True and specifing the server u"server": "chat.facebook.com"
handler = MyHandler(JID(target_jid), message)
settings = XMPPSettings({
u"ipv4": True,
u"server": "chat.facebook.com",
u"password": your_password,
u"starttls": True,
u"tls_verify_peer": False,
})
client = Client(JID(your_jid), [handler], settings)
client.connect()
client.run()
The full code is located on the pyxmpp2 examples folder send_message_client.py

Rabbitmq connection issue when using a username and password

I am trying to start some background processing through rabbitmq, but when I send the request, I get the below error in the rabbitmq log. But, I think I am providing the right credentials, as my celery works are able to connect to rabbitmq server using the same username/password combination.
=ERROR REPORT==== 12-Jun-2012::20:50:29 ===
exception on TCP connection from 127.0.0.1:41708
{channel0_error,starting,
{amqp_error,access_refused,
"AMQPLAIN login refused: user 'guest' - invalid credentials",
'connection.start_ok'}}
To get resolve connection with rabbitmq need to inspect below points:
Connectivity from client machine to rabbitmq server machine [in case if client and server are running on separate machine], need to check
along with port as well.
Credential (username and password), a user must be onboarded into RabbitMQ which will be used to connect with RabbitMQ
Permission to User must be given (permission may be attached to VHOST as well so need to provide permission carefully)
The best way to debug permissions issues in the amqp protocol is to look at the request:
transport://userid:password#hostname:port/virtual_host
from http://docs.celeryproject.org/en/latest/configuration.html#conf-broker-settings

closing a socks/proxy connection in python

I am writing some code that uses poplib and imaplib to collect emails through a proxy server.
I use the following to set up a proxy connection:-
import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4,proxy_ip,port,True)
socket.socket = socks.socksocket
Which I got from the stackoverflow post:-
http://stackoverflow.com/questions/3386724/python-how-can-i-fetch-emails-via-pop-or-imap-through-a-proxy
Then I make my connection with the email server:-
server = poplib.POP3(self.host, self.port)
server.user(self.username)
server.pass_(self.password)
I am testing my code in a unittest and have encountered a problem that I believe relates to my connection with the proxy not closing down properly.
An example is:-
I have set up the proxy connection and am trying to establish a connection with the email server. As part of the unittest I intentionally use an incorrect email server password.
The poplib library throws an exception that it can't connect. I catch the exception in the unittest, then move on to the next unittest, trusting the poplib library would properly close my previous connection.
My understanding is that this is not a good thing and that I should be ensuring the email and proxy server connections are properly closed.
I know how to close the pop3 connection:-
server.quit()
But do not know how to close the connection with the proxy server or if I have to do so.
Could someone please help me with this question or with my understanding if that's where the problem lies :)
No special action is required. When you close the POP connection, the proxy connection will close automatically, since it's only needed while you are connected to something through the proxy.

Categories