It's slow to send email by the default EmailBackend of django 1.11 using Microsoft business email account - django

I'm using the default EmailBackend of Django 1.11, I just simply called the send_mail method as the ref. document said, here are my settings of the SMTP server:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_PORT = '587'
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'oalite#xxx.com'
EMAIL_HOST_PASSWORD = 'xxxxx'
EMAIL_SUBJECT_PREFIX = '[OALite Admin]'
Here is my log outputted by smtplib.py:
reply: b'250-CHUNKING\r\n'
reply: b'250 SMTPUTF8\r\n'
reply: retcode (250); Msg: b'SG2PR06CA0180.outlook.office365.com Hello [85.203.47.85]\nSIZE 157286400\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\nAUTH LOGIN XOAUTH2\n8BITMIME\nBINARYMIME\nCHUNKING\nSMTPUTF8'
send: 'AUTH LOGIN b2FBaXRl0GlyaXhpLmNvb0==\r\n'
reply: b'334 UGFzc3dvcmQ6\r\n'
reply: retcode (334); Msg: b'UGFzc3dvcmQ6'
send: 'QEdBbH1w0DJuSwY=\r\n
>>>>>>>>>>>>>>>>>> halted here for about 15s to wait the reply <<<<<<<<<<<<<<<<<<<
reply: b'235 2.7.0 Authentication successful target host BLUPR04MB420.namprd04.prod.outlook.com\r\n'
reply: retcode (235); Msg: b'2.7.0 Authentication successful target host BLUPR04MB420.namprd04.prod.outlook.com'
send: 'mail FROM:<oalite#xxx.com> size=943\r\n'
reply: b'250 2.1.0 Sender OK\r\n'
reply: retcode (250); Msg: b'2.1.0 Sender OK'
send: 'rcpt TO:<user.foo#xxx.com>\r\n'
reply: b'250 2.1.5 Recipient OK\r\n'
Please note that I was using the business email account of Microsoft, the domain xxx.com actually is our company domain name.
I have no idea why it took 15s to authenticate, it's very fast to send emails using the outlook desktop app with the same account. Is it faster to use Exchange protocol then to use SMTP protocol?
Thanks for your help!

A few options for quickly sending outgoing mail from views, when authentication is slow:
Use celery to offload mail sending to an offline task.
Install a local (forwarding) mail server on your host. On linux this can be accomplished easily with postfix. You can configure the mail server to connect to your business email account.
Both :-)
There seems to be a REST API to connect to outlook.com - so you can also write your own mail backend for sending mail via HTTP.

Related

How can I set [output_adapter.email] with Aruba address in wso2 Identity Server v. 5.11.0?

I'm trying to set an email sender (for example recovery password). I already set with a Gmail and Outlook address mail and it's work!
Now i nedd to configure an Aruba hostmail.
this is my deployment.toml configuration module
[output_adapter.email]
from_address= "****#aruba.it"
username= "*****#****.it"
password= "******"
hostname= "smtps.aruba.it"
port= 465
enable_start_tls= true
enable_authentication= true
signature = "****"
[output_adapter.email.custom_properties]
"mail.smtp.ssl.protocols"="TLSv1.2"
"mail.transport.protocol"="smtps"
Logs return
ERROR {org.wso2.carbon.event.output.adapter.email.EmailEventAdapter} - Event dropped at Output Adapter 'EmailPublisher' for tenant id '-1234', Error in message format, Could not connect to SMTP host: smtps.aruba.it, port: 465, response: -1 javax.mail.MessagingException: Could not connect to SMTP host: smtps.aruba.it, port: 465, response: -1
I tried with smpts and smpt (it should be the same port 465).
Can you tell me if it's not supported or something?
THanks, i really need help :(
I fixed it by adding these properties in deployment.toml file below this modules:
[output_adapter.email]
from_address= "***#aruba.it"
username= "****"
password= "****!"
hostname= "smtps.aruba.it"
port= 465
enable_start_tls= true
enable_authentication= true
signature = "WSO2"
[output_adapter.email.custom_properties]
"mail.smtp.ssl.protocols"="TLSv1.2"
"mail.smtp.debug"="true"
"mail.smtp.socketFactory.port"="465"
"mail.smtp.socketFactory.class"="javax.net.ssl.SSLSocketFactory"
"mail.smtp.socketFactory.fallback"="false"

OJS SMTPMailer: Could not authenticate, OJS 2.4.8.1 with AWS SES

I'm using OJS 2.4.8.1, therefore, I want to use the AWS SES SMTP Service, so, I've configured the config file config.inc.php as follow:
; Use SMTP for sending mail instead of mail()
smtp = On
; SMTP server settings
smtp_server = email-smtp.us-east-1.amazonaws.com
smtp_port = 587
; Force the default envelope sender (if present)
; force_default_envelope_sender = On
; Enable SMTP authentication
; Supported mechanisms: PLAIN, LOGIN, CRAM-MD5, and DIGEST-MD5
smtp_auth = PLAIN
smtp_username = XXXXXXXXXX
smtp_password = XXXXXXXXXX/XXXXXXXXX
; Allow envelope sender to be specified
; allow_envelope_sender = On
After sending a test I can view in error_log the following:
OJS SMTPMailer: Could not authenticate
NOTES: the username and password are correct, I tried adding the params with/without quotes, I tried with 25, 465 or 587 ports and nothing works.
Any help is well received.

Email on failure using AWS SES in Apache Airflow DAG

I am trying to have Airflow email me using AWS SES whenever a task in my DAG fails to run or retries to run. I am using my AWS SES credentials rather than my general AWS credentials too.
My current airflow.cfg
[email]
email_backend = airflow.utils.email.send_email_smtp
[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = emailsmtpserver.region.amazonaws.com
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
smtp_user = REMOVEDAWSACCESSKEY
smtp_password = REMOVEDAWSSECRETACCESSKEY
smtp_port = 25
smtp_mail_from = myemail#myjob.com
Current task in my DAG that is designed to intentionally fail and retry:
testfaildag_library_install_jar_jdbc = PythonOperator(
task_id='library_install_jar',
retries=3,
retry_delay=timedelta(seconds=15),
python_callable=add_library_to_cluster,
params={'_task_id': 'cluster_create', '_cluster_name': CLUSTER_NAME, '_library_path':s3000://fakepath.jar},
dag=dag,
email_on_failure=True,
email_on_retry=True,
email=’myname#myjob.com’,
provide_context=True
)
Everything works as designed as the task retries the set number of times and ultimately fails, except no emails are being sent. I have checked the logs in the task mentioned above too, and smtp is never mentioned.
I've looked at the similar question here, but the only solution there did not work for me. Additionally, Airflow's documentation such as their example here does not seem to work for me either.
Does SES work with Airflow's email_on_failure and email_on_retry functions?
What I am currently thinking of doing is using the on_failure_callback function to call a python script provided by AWS here to send an email on failure, but that is not the preferable route at this point.
Thank you, appreciate any help.
--updated 6/8 with working SES
here's my write up on how we got it all working. There is a small summary at the bottom of this answer.
Couple of big points:
We decided not to use Amazon SES, and rather use sendmail We now have SES up and working.
It is the airflow worker that services the email_on_failure and email_on_retry features. You can do journalctl –u airflow-worker –f to monitor it during a Dag run. On your production server, you do NOT need to restart your airflow-worker after changing your airflow.cfg with new smtp settings - it should be automatically picked up. No need to worry about messing up currently running Dags.
Here is the technical write-up on how to use sendmail:
Since we changed from ses to sendmail on localhost, we had to change our smtp settings in the airflow.cfg.
The new config is:
[email]
email_backend = airflow.utils.email.send_email_smtp
[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = localhost
smtp_starttls = False
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
#smtp_user = not used
#smtp_password = not used
smtp_port = 25
smtp_mail_from = myjob#mywork.com
This works in both production and local airflow instances.
Some common errors one might receive if their config is not like mine above:
socket.error: [Errno 111] Connection refused -- you must change your smtp_host line in airflow.cfg to localhost
smtplib.SMTPException: STARTTLS extension not supported by server. -- you must change your smtp_starttls in airflow.cfg to False
In my local testing, I tried to simply force airflow to show a log of what was going on when it tried to send an email – I created a fake dag as follows:
# Airflow imports
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from airflow.operators.bash_operator import BashOperator
from airflow.operators.dummy_operator import DummyOperator
# General imports
from datetime import datetime,timedelta
def throwerror():
raise ValueError("Failure")
SPARK_V_2_2_1 = '3.5.x-scala2.11'
args = {
'owner': ‘me’,
'email': ['me#myjob'],
'depends_on_past': False,
'start_date': datetime(2018, 5,24),
'end_date':datetime(2018,6,28)
}
dag = DAG(
dag_id='testemaildag',
default_args=args,
catchup=False,
schedule_interval="* 18 * * *"
)
t1 = DummyOperator(
task_id='extract_data',
dag=dag
)
t2 = PythonOperator(
task_id='fail_task',
dag=dag,
python_callable=throwerror
)
t2.set_upstream(t1)
If you do the journalctl -u airflow-worker -f, you can see that the worker says that it has sent an alert email on the failure to the email in your DAG, but we were still not receiving the email. We then decided to look into the mail logs of sendmail by doing cat /var/log/maillog. We saw a log like this:
Jun 5 14:10:25 production-server-ip-range postfix/smtpd[port]: connect from localhost[127.0.0.1]
Jun 5 14:10:25 production-server-ip-range postfix/smtpd[port]: ID: client=localhost[127.0.0.1]
Jun 5 14:10:25 production-server-ip-range postfix/cleanup[port]: ID: message-id=<randomMessageID#production-server-ip-range-ec2-instance>
Jun 5 14:10:25 production-server-ip-range postfix/smtpd[port]: disconnect from localhost[127.0.0.1]
Jun 5 14:10:25 production-server-ip-range postfix/qmgr[port]: MESSAGEID: from=<myjob#mycompany.com>, size=1297, nrcpt=1 (queue active)
Jun 5 14:10:55 production-server-ip-range postfix/smtp[port]: connect to aspmx.l.google.com[smtp-ip-range]:25: Connection timed out
Jun 5 14:11:25 production-server-ip-range postfix/smtp[port]: connect to alt1.aspmx.l.google.com[smtp-ip-range]:25: Connection timed out
So this is probably the biggest "Oh duh" moment. Here we are able to see what is actually going on in our smtp service. We used telnet to confirm that we were not able to connect to the targeted IP ranges from gmail.
We determined that the email was attempting to be sent, but that the sendmail service was unable to connect to the ip ranges successfully.
We decided to allow all outbound traffic on port 25 in AWS (as our airflow production environment is an ec2 instance), and it now works successfully. We are now able to receive emails on failures and retries (tip: email_on_failure and email_on_retry are defaulted as True in your DAG API Reference - you do not need to put it into your args if you do not want to, but it is still good practice to explicitly state True or False in it).
SES now works. Here is the airflow config:
[email]
email_backend = airflow.utils.email.send_email_smtp
[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = emailsmtpserver.region.amazonaws.com
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
smtp_user = REMOVEDAWSACCESSKEY
smtp_password = REMOVEDAWSSECRETACCESSKEY
smtp_port = 587
smtp_mail_from = myemail#myjob.com (Verified SES email)
Thanks!
Similar case here, I tried to follow the same debugging process but got no log output. Also, the outbound rule for my airflow ec2 instance is open to all ports and ips, so it should be some other causes.
I noticed that when you create the SMTP credential from SES, it will also create an IAM user. I am not sure how is airflow running in your case (bare metal on ec2 instance or wrapped in containers), and how that user access is set up.

How to setup outgoing mail server through outlook office365 in odoo 9

I will try to setup outgoing mail server in odoo 9 .so i fill all the field and test connection and the connection also success , but at the time of send mail it will generate an error .
Field fill like that:-
Name : sendmail
Priority: 10
SMTP Server : smtp.office365.com
SMTP Port:25
Debugging: enable
Connection Security:TLS (STARTTLS)
Username:my yser name
Password:password
But, when we send any mail then it will generate the below error
16-12-06 10:04:28,440 426 INFO test openerp.addons.base.ir.ir_mail_server: Mail delivery failed via SMTP server 'smtp.office365.com'.
SMTPDataError: 550
5.7.60 SMTP; Client does not have permissions to send as this sender
2016-12-06 10:04:28,443 426 ERROR test openerp.addons.mail.models.mail_mail: failed sending mail (id: 136) due to Mail Delivery Failed
Mail delivery failed via SMTP server 'smtp.office365.com'.
SMTPDataError: 550
5.7.60 SMTP; Client does not have permissions to send as this sender
Traceback (most recent call last):
File "/usr/lib/python2.7/dist- packages/openerp/addons/mail/models/mail_mail.py", line 262, in send
res = IrMailServer.send_email(msg, mail_server_id=mail.mail_server_id.id)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 490, in new_api
result = method(self._model, cr, uid, *args, **old_kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_mail_server.py", line 483, in send_email
raise MailDeliveryException(_("Mail Delivery Failed"), msg)
MailDeliveryException: (u'Mail Delivery Failed', u"Mail delivery failed via SMTP server 'smtp.office365.com'.\nSMTPDataError: 550\n5.7.60 SMTP; Client does not have permissions to send as this sender")
So i tried too much for this , but i am not getting any solution , if you have any solutin , please share with me .
Use port 587.
The error message tells you that the sender is invalid - you can only send as the mailbox owner (primary SMTP address) or as one of the proxy addresses associated with the mailbox.
Removing all catchall parameters (mail.catchall.domain and mail.catchall.alias) under "Settings" -> "Technical" -> "Parameters" -> "System Parameters" and it work like charm .
WORKS LIKE CHARM :
Removing all catchall parameters (mail.catchall.domain and mail.catchall.alias) under "Settings" -> "Technical" -> "Parameters" -> "System Parameters" and it work like charm . TY Debasish
I'm on Odoo V12
It was not suffisient for my problem, I had to delete the alias domain but there another thing to check :
I initialy created my odoo installation with a GMAIL address, worked a bit but had to switch for a pro e-mail because all my invitations e-mail was blocked by Google Bot beacause it look liked suspicious. It did this only in Odoo v12 because there is more links in the mail.
So I configured my real smtp server in Odoo but get the error 550. Odoo kept in the COMPANY settings the primary gmail address and tried to send on my other smtp server with the gmail name. The other server didn't accepted it so sent me back error 550.
Once i putted my new e-mail address in the company description, and deleted alias domain it worked !!
PS : Don't try to edit ir_mail_server.py to put in bruteforce your e-mail ... Doesn't work ..

How do I send email using php via wamp?

I want to use wamp as my development server and I'm trying to send email via my email => gmail, hotmail, yahoo. I'm trying to implement a simple email php application.
Is it possible to do it in wamp?
Is it possible to do it without changing php.ini and instead use ini_set();
I have tried changing my php.ini
using my yahoo mail
SMTP = smtp.mail.yahoo.com
; http://php.net/smtp-port
smtp_port = 587
auth_user = me#yahoo.com
auth_pass = password
and got this error message "Warning: mail() [function.mail]: SMTP server response: 530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html in C:\wamp\www\9dot_disc_alt\abc.php on line 12"
using gmail
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 587
auth_user = me#gmail.com
auth_pass = password
SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. pc6sm6631754pbc.47 in C:\wamp\www\9dot_disc_alt\abc.php on line 12
Here's my current code:
$to = "me#yahoo.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "me#my.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
Sir/Ma'am your answers would be of great help and be very much appreciated. Thank you++
When you use wamp, your SMTP must be your FAI, for example if you have free :
=>SMTP = smtp.free.fr (or .com)
EDIT : You can try this : http://glob.com.au/sendmail/, i's a simple windows console application that emulates sendmail's for wamp for example ;)
I found an online article that allows me to send emails using wamp + php mailer
http://nikunj-solutions.blogspot.com/2011/08/send-email-using-wamp-server.html