How to send an email with Ansible - email

I'm trying to send an email using Ansible, but I can't understand how it works as I don't know how to provide user and password for such service (not specified in the documentation).
Both my machine and the email server are in the same network, but I need to be authenticated in order to send the email.
This is my yml file:
---
- name: Testing email
hosts: localhost
tasks:
- name: Send email
local_action: mail
host=mail.server.com
port=993
subject="Ansible test mail"
body="Testing email"
from=my#email
to="y#email
charset=utf8
And this is the related content of the hosts' file:
[localhost]
localhost ansible_connection=local
Any idea about how should I configure it? Thanks in advance.

Looking at the source code for the mail module ( https://github.com/ansible/ansible/blob/d1effecb2ef073e478c67a7ca39cf56708a66a48/library/notification/mail ) it doesn't look like it supports SMTP authentication.
It shouldn't be too hard to add support for it however. It would require adding the username and password parameters to the module, detecting if they've both been supplied, and if so, calling smtp.login() with those parameters.
In fact, it looks like there's two pull requests to do exactly that at the moment here
https://github.com/ansible/ansible/pull/7213
and here
https://github.com/ansible/ansible/pull/6667
So support will most likely be added in dev soon.

Related

Jenkins email plugin doesn't send email to user who broke the build

I've setup Jenkins to send emails only to users who broke the build using email-ext plugin, but I'm getting this error:
Not sending mail to unregistered user user#example.com because your SCM claimed this was associated with a user ID ‘John Smith' which your security realm does not recognize; you may need changes in your SCM plugin
I don't really understand what this error means, is the problem in our SCM, or in the email plugin? The emails are taken from the commit history, should I register them somewhere so Jenkins will start working?
For reference, this is the code around the error message in the plugin's source code:
} catch (UsernameNotFoundException x) {
if (SEND_TO_UNKNOWN_USERS) {
listener.getLogger().printf("Warning: %s is not a recognized user, but sending mail anyway%n", userAddress);
} else {
listener.getLogger().printf("Not sending mail to unregistered user %s because your SCM"
........
How do I enable SEND_TO_UNKNOWN_USERS?
The error message is also mentioned in this bug report.
For version V2.61 or above this can be configured via a radio button.
Go to
Manage Jenkins -> Configure System -> Extended E-mail Notification
and tick the radio button for Allow sending to unregistered users
Edit: If this does not work, see https://stackoverflow.com/a/45353810/492336 for another solution.
OK, after some experiments this is what I found out:
Jenkins takes the email part of the committer (not the author). For example for a commit message that looks like that:
Author: John Smith <author1#example1.com> 2017-07-27 17:15:39
Committer: John Doe <committer1#example2.com> 2017-07-27 17:15:39
Parent: 9c3ff18dda8ca6f7b7ac4ebab4c76d3c85891a33 (commit)
Branch: master
Jenkins will take "committer1", and create a brand new user under People with User ID "committer1" and email "". Unless that user has a password however, it will be considered unregistered so you need to go to Configure for that user and add a password field to it:
So this is one way to fix the error, but you have to do it for every user and in a big team it can be tedious.
Put the line bellow in your jenkins startup script
-Dhudson.tasks.MailSender.SEND_TO_UNKNOWN_USERS=true
The newest Jenkins security directive only allow sending mail to registered user. The line above bypass this configuration.
Given jenkins takes the first part of the email address and creates a user, I made my team have their jenkins user name be the first part of their email address. This removed any overhead of having to maintain two separate users.

Sitecore custom MTA for localhost

I am trying to figure out EXM for Sitecore. I installed it and now I am trying to configure it to send emails from my local machine. SAC MTA is not an option because I don't have access to App Center. I am left with custom MTA.
I was trying to configure config files to use gmail smtp:
Sitecore.EDS.Providers.CustomSmtp.config
<smtpSettings type="Sitecore.EDS.Core.Net.Smtp.SmtpSettings, Sitecore.EDS.Core" singleInstance="true">
<server>smtp.gmail.com</server>
<port>465</port>
<userName>*****#gmail.com</userName>
<password>*****</password>
<authenticationMethod>Login</authenticationMethod>
<startTls>true</startTls>
<proxySettings ref="exm/eds/proxySettings" />
</smtpSettings>
Sitecore.EDS.Providers.CustomSmtp.Sync.config
<pop3Settings>
<pop3Setting type="Sitecore.EDS.Core.Net.Pop3.Pop3Settings, Sitecore.EDS.Core" singleInstance="true">
<server>pop.gmail.com</server>
<port>995</port>
<userName>****#gmail.com</userName>
<password>****</password>
<useSsl>true</useSsl>
<startTls>true</startTls>
<proxySettings ref="exm/eds/proxySettings"/>
</pop3Setting>
</pop3Settings>
But when I try to "send quick test" through EXM I get "Failed to connect to the email server. Please try again later". Can anyone help me with that configuration. And is it even possible? I remember reading something about paid license to use custom MTA. Would it mean, that you need to pay to send email via EXM?
To switch from using the Sitecore MTA to using the Custom SMTP, you must disable the Dyn configurations and then enable the CustomSmtp configurations:
In the Website\App_Config\Include\EmailExperience folder, add the suffix .disabled to the end of the following file names:
Sitecore.EDS.Providers.Dyn.config
Sitecore.EDS.Providers.Dyn.Sync.config
In the  Website\App_Config\Include\EmailExperience folder, remove the suffix .disabled from the following file names:
Sitecore.EDS.Providers.CustomSmtp.config.disabled
Sitecore.EDS.Providers.CustomSmtp.Sync.config.disabled

What else is needed to use gitlab 7.1.1 external smtp email settings?

I know that, to use smtp in gitlab 7.1.1, you need the following config; In:
/home/git/gitlab/config/gitlab.yml
edit following line
## Email settings
# Email address used in the "From" field in mails sent by GitLab
email_from: account#your-mail-server.com
and rename this file
/home/git/gitlab/config/initializers/smtp_settings.rb.sample
to
/home/git/gitlab/config/initializers/smtp_settings.rb
and edit following settings:
ActionMailer::Base.smtp_settings = {
address: "email.server.com",
port: 456,
user_name: "smtp",
password: "123456",
domain: "gitlab.company.com",
authentication: :login,
enable_starttls_auto: true
}
and restart GitLab instance.
Is there other points you need to be aware in order to use smtp-based email with GitLab 7.x?
Note that:
config/initializers/smtp_settings.rb has been added to .gitignore only recently (GitLab 7.0+, PR 7062, commit a727d25)
issue 6023 does mention:
Gitlab uses the system configured sendmail to issue emails to users.
The recommended method is to configure your host sendmail so that it properly works and then Gitlab will successfully email as a result.
If configuring sendmail is not desirable, then Gitlab provides smtp_settings.rb which can be used to override default Gitlab email settings.
This uses ruby net::smtp to configure email.
In order to properly configure it one must know the available SMTP AUTH methods allowed by their mail provider. ruby net::smtp supports only three auth schemes: PLAIN, LOGIN, and CRAM MD5.
issue 6845 reminds us:
If you're using SMTP, make sure you change:
config.action_mailer.delivery_method = :sendmail
to
config.action_mailer.delivery_method = :smtp
in the config/environments/production.rb file.

Debian - invoke external script from exim on receipt of emails

I am looking fopointers on the best approach to process incoming emails to a certain vhost and to call an external script with the email data as parameters - basically to allow email to be sent to a certain "private" email address at a host which then auto inserts something into that sites database. I currently have exim set up as the mail handler.
You have to follow exim single file configurations structure. In routers section write your own custom router that will deliver email to your desired php script. In transport section write your own custom transport that will ensure delivery to the desired script using curl. Just write the following configurations in your /etc/exim.cnf file:
############ROUTERS
runscript:
driver = accept
transport = run_script
unseen
no_expn
no_verify
############TRANSPORT
run_script:
debug_print = "T: run_script for $local_part#$domain"
driver = pipe
command = /home/bin/curl http://my.domain.com/mailTest.php --data-urlencode $original_local_part#$original_domain
Where mailTest.php will be your destined script.
Procmail is a good generic answer. If your needs are very specific, you could hook in your own script directly from your .forward (or Exim's corresponding construct -- can't remember exactly how it differs), but oftentimes, wrapping your own script inside a simple .procmailrc helps you avoid a bunch of iffy details of email delivery, and concentrate on the actual processing.
:0
' ^Subject: secretpassword adduser \/[A-Z]+
| echo "insert $MATCH into users" | mysql -d users

Catchall Router on Exim does not work

I have setup a catchall router on exim (used as last router):
catchall:
driver = redirect
domains = +local_domains
data = ${lookup{*#$domain}lsearch{/etc/aliases}}
retry_use_local_part
This works perfectly when sending emails locally. However, if I login to my GMail account and send an email to whatever#mydomain.com, then I get an "Unrouteable Address".
Thank you for any hints to solve this issue.
In the system_aliases: section of the config file you already have a section which does the lookup in /etc/aliases.
Replace
data = ${lookup{$local_part}lsearch{/etc/aliases}}
with
data = ${lookup{$local_part}lsearch*#{/etc/aliases}}
and make sure you have *:catchall_username* in /etc/aliases
This works great for a single domain mail server which is already using /etc/aliases
For this router to work, make sure that
mydomain.com is in local_domains
there is an entry for *#mydomain.com in /etc/aliases
MX record for mydomain.com is pointing to the server, where you've
configured this
This is old as heck, but I didn't see a good answer posted and someone else might want to know the answer.
This post is geared towards Debian with in single configuration file mode. It should work on any Linux Exim4 install though. For the purpose of explaining things we’ll use test#example.com which is configured with the hostname mail.example.com. The system will have a real user called test and we want to create an alias for test called alias. So the end result will all email sent to alias#example.com forwarded to test#example.com without having to create the user alias on the system.
First we need to create a place to store all of the alias files:
mkdir /etc/exim/aliases.d
vim /etc/exim/aliases.d/mail.example.com
contents of the alias file for mail.example.com alias:test
vim /etc/exim/exim4.conf.template
Now look for the section system_aliases. Here you’ll see data = ${lookup{$local_part}lsearch{/etc/aliases}} or something similar. Change that to
data = ${lookup{$local_part}lsearch{/etc/exim4/aliases.d/$domain}}
Save the file and restart exim. The alias should now work. To add support for other domains just add more alias files in the aliases.d directory with the correct hostname.
I copied and pasted this from my blog:
0xeb.info