Ansible mail module not working with office 365 - email

I am trying to send send an email from ansible
If I try it with gmail it works perfectly, However If I try with office 365 its not working.
Below is my Playbook.
---
- name: Mail Sendig using Ansible
hosts: localhost
tasks:
- name: Mail sending using Mail Module
mail:
host: "smtp.office365.com"
port: 587
username: "dcalert#mycompany.com"
password: "mypasswd"
to: "Jon Snow <jon.snow#mycompany.com>"
subject: "Ansible"
body: "Hello from Ansible"
secure: starttls
I am getting below error
ASK [Send email]
*******************************************************************
An exception occurred during task execution. To see the full
traceback, use -vvv. The error was: SMTPSenderRefused: (501, '5.1.7
Invalid address', 'root')
fatal: [localhost -> localhost]: FAILED! => {"changed": false,
"failed": true, "msg": "Failed to send mail to
jon.snow#mycompany.com: (501, '5.1.7 Invalid address',
'root')", "rc": 1}

You're missing fromparameter...
Take a look here: Ansible Mail Module
It says the parameter from defaults to root. Since you're not setting it, mail server says its invalid. Probably gmail doesnt handle it the same way as office365.
Give this a try...
---
- name: Mail Sendig using Ansible
hosts: localhost
tasks:
- name: Mail sending using Mail Module
mail:
host: "smtp.office365.com"
port: 587
username: "dcalert#mycompany.com"
password: "mypasswd"
from: "dcalert#mycompany.com"
to: "Jon Snow <jon.snow#mycompany.com>"
subject: "Ansible"
body: "Hello from Ansible"
secure: starttls

Related

Swiftmailer email issue

I am sending email in Symfony2 using Swift Mailer.
//app/config.yml
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
port: "%mailer_port%"
encryption: "%mailer_encryption%"
spool: { type: memory }
And app/parameters.yml
mailer_transport: smtp
mailer_host: smtp.office365.com
mailer_user: notify#location.com
mailer_password: test
mailer_port: 587
mailer_encryption: tls
But I am getting following error again- and again.
app.ERROR: Exception occurred while flushing email queue: Expected response code 250 but got code "", with message "" [] []
How can I resolve this?
"SMTP error 554 is one of the more vague error codes, but is typically caused by the receiving server seeing something in the From or To headers that it doesn't like. This can be caused by a spam trap identifying your machine as a relay, or as a machine not trusted to send mail from your domain." - STMP error 554

Gitlab not sending email

I've installed gitlab ce on docker with the documentation, everything is ok but mails doesn't works in gitlab (ask for new password for example).
When I test my conf in the rail-console I get the mail, when gitlab is supposed to send email, it doesn't works.
For mail I use OVH SMTP conf, my smtp_settings.yml is ok
see by yourself :
# This file is managed by gitlab-ctl. Manual changes will be
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
# and run `sudo gitlab-ctl reconfigure`.
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
authentication: :login,
address: "ssl0.ovh.net",
port: 465,
user_name: "myemail#domain.dn",
password: "mypassword",
domain: "ssl0.ovh.net",
enable_starttls_auto: true,
tls: true,
openssl_verify_mode: "peer",
ca_file: "/opt/gitlab/embedded/ssl/certs/cacert.pem",
}
end
I already tried openssl_verify_mode: "peer" and "none"
Any idea ? I'm on it from about a month.

not able to send the email -POP3/SMTP in blue prism

In my "Configure" action inputs (Business Object: Email - POP3/SMTP):-
Username: xxx#gmail.com
password: xxxx
POP3 Server: pop.gmail.com
SMTP Server: smtp.gmail.com
POP3 Port: 995
SMTP Port: 587
POP3 UseSSL: True
SMTP UseSSL: True
Error:- "Internal: Could not execute code stage because the exception is thrown by code stage: The SMTP server requires a secure connection or the client was not authenticated"
Tried SMTP Port: 465 and still facing an error:
"Internal: Could not execute code stage because an exception is thrown by code stage. Failure sending mail. - Unable to read data from the transport connection: net_io_connectionclosed"
You need to update you security in google
Login your google account and go to security tab there you find somewhere first Turn On Access for less secure apps in the gmail account.
Hope this will work!

Jhipster - Configuring Email with Zoho - Error 553 Relaying disallowed

I am new to Jhipster and trying to configure zoho and I am getting errors.
My setting in /myjhipsterapplicationname/src/main/resources/config/application-dev.yml
mail:
host: smtp.zoho.com
port: 587
username: ****#myCustomDomainOnZoho.com
password: ****** // My password for the above email
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.zoho.com
Errors, I am receiving
2017-03-02 21:15:13.421 WARN 6192 --- [ints-Executor-2] com.nectotech.com.service.MailService : E-mail could not be sent to user 'asif#nectotech.com'
org.springframework.mail.MailSendException: Failed to close server connection after message failures; nested exception is javax.mail.MessagingException: Can't send command to SMTP host;
nested exception is:
java.net.SocketException: Connection closed by remote host. Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 553 Relaying disallowed as breakpoints#localhost
I tried the following and it worked.
Go to /myjhipsterapplicationname/src/main/resources/config/application-dev.yml
Search for
mail: # specific JHipster mail property, for standard properties see MailProperties
from:
Replace the value of property from: with your SMTP outgoing email address

Grails mail plugin issues with Gmail SMTP

I'm using the grails mail plugin (2.0.0.RC2) with Grails 3.0.7. This is my config:
mail:
host: smtp.gmail.com
port: 465
username: myuser#gmail.com
password: myPassword
props:
- mail.debug: true
- mail.smtp.auth: true
- mail.smtp.socketFactory.port: 465
- mail.smtp.socketFactory.class: javax.net.ssl.SSLSocketFactory
- mail.smtp.socketFactory.fallback: false
When I try to send a test mail, I get the following error:
Caused by: org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at grails.plugins.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:131) ~[mail-2.0.0.RC2.jar:na]
at grails.plugins.mail.MailService.sendMail(MailService.groovy:55) ~[mail-2.0.0.RC2.jar:na]
at grails.plugins.mail.MailService.sendMail(MailService.groovy:59) ~[mail-2.0.0.RC2.jar:na]
at com.eduspace.ClassroomController.$tt__index(ClassroomController.groovy:13) ~[main/:na]
at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.0.7.jar:3.0.7]
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:90) ~[grails-core-3.0.7.jar:3.0.7]
... 9 common frames omitted
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1972) ~[javax.mail-1.5.1.jar:1.5.1]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656) ~[javax.mail-1.5.1.jar:1.5.1]
at javax.mail.Service.connect(Service.java:345) ~[javax.mail-api-1.5.1.jar:1.5.1]
... 15 common frames omitted
I see no other debug information in the logs. I have the root logger set to INFO, so everything should be getting outputted. I've verified that I can telnet to smtp.gmail.com port 465, so that's not the issue. I've read that others have had issues with SSL, but then there's usually some debug information indicating an SSL issue and I don't get anything like that.
I am using a slightly different config that works fine:
grails:
mail:
host: "smtp.gmail.com"
port: 465
username: "<username>#gmail.com"
password: "<password>"
props:
mail.smtp.auth: "true"
mail.smtp.socketFactory.port: "465"
mail.smtp.socketFactory.class: "javax.net.ssl.SSLSocketFactory"
mail.smtp.socketFactory.fallback: "false"
The mail config is inside in the grails placeholder and i am not using the dashes as in your example. Maybe this could be of help to you.
This could ofcourse be wrong due to config error but one of the reason for this exact error message is gmail configuration. To avoid spam messages, gmail has started blocking access from apps that do not conform to latest security guidelines.
One easy way to avoid this error is to go to your gmail account and allow less secure apps.- https://www.google.com/settings/security/lesssecureapps
Your configuration looks good.
Here is the mine working fine:
grails {
mail {
host = "smtp.gmail.com"
'default' {
from = "<username>#gmail.com"
}
port = 465
username = "<username>#gmail.com"
password = "<password>"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}