Using GMAIL to send mail with the Mail Action 1.9.0.b5

I’ve spent almost two days trying to make this easy job done, I just wanted to send an email from a rule.

I’ve read the docs and several post around and this was the mail.cfg file I found everywhere and it’s also the default file that cames with OH2, but this one does NOT WORK.

######################## Mail Action configuration ####################################
#
# The SMTP server hostname, e.g. "smtp.gmail.com"
mail:hostname=smtp.gmail.com

# the SMTP port to use (optional, defaults to 25 (resp. 587 for TLS))
mail:port=587

# the username and password if the SMTP server requires authentication
mail:username=xxxxxxxxx@gmail.com
mail:password=xxxxxxxx

# The email address to use for sending mails
mail:from=xxxxxxxxx@gmail.com

# set to "true", if TLS should be used for the connection
# (optional, defaults to false)
mail:tls=true

# set to "true", if POP before SMTP (another authentication mechanism)
# should be enabled. Username and Password are taken from the above
# configuration (optional, default to false)
#mail:popbeforesmtp=

Well, after capturing the traffic generated from my server with TCPDUMP, I’ve realized that even the docs says that the property mail:popbeforesmtp defaults to false this is WRONG by default this property is TRUE and thats why it didn’t work, so the proper mail.cfg should look like this if you want to connect to GMAIL.

######################## Mail Action configuration ####################################
#
# The SMTP server hostname, e.g. "smtp.gmail.com"
mail:hostname=smtp.gmail.com

# the SMTP port to use (optional, defaults to 25 (resp. 587 for TLS))
mail:port=587

# the username and password if the SMTP server requires authentication
mail:username=xxxxxxxxx@gmail.com
mail:password=xxxxxxxx

# The email address to use for sending mails
mail:from=xxxxxxxxx@gmail.com

# set to "true", if TLS should be used for the connection
# (optional, defaults to false)
mail:tls=true

# set to "true", if POP before SMTP (another authentication mechanism)
# should be enabled. Username and Password are taken from the above
# configuration (optional, default to false)
mail:popbeforesmtp=false

Now, my OH" is sending email lika a charm… :slight_smile:

Hope this helps someone…

3 Likes

Would be great if you could open an issue here:

so the docs gets changed.

just to note that I have not changed this value (default is false) and it worked right from the start. Have set up two gmail accounts in two openhab installations without issues

@cgeo which version of Action Mai are you using? 1.9.0.b5?

PaperUI reports 1.9.0. It is the one that comes with the stable 2.0 release
How can I see the details ?

I started working with mail for the first time today and i didnt really have that issue. Worked right out of the box.
config file looks like this:

    # The SMTP server hostname, e.g. "smtp.gmail.com"
    hostname=smtp.gmail.com
    port=587
    username=xxxxxx
    password=yyyyyy
    from=xxxxx@gmail.com

    # set to "true", if STARTTLS is enabled (not required) for the connection
    # (optional, defaults to false)
    tls=TRUE

    # set to "true", if SSL negotiation should occur on connection
    # do not use both tls=true and ssl=true
    # (optional, defaults to false)
    #ssl=

    # set to "true", if POP before SMTP (another authentication mechanism)
    # should be enabled. Username and Password are taken from the above
    # configuration (optional, default to false)
    #popbeforesmtp=

    #charset=

i left the popbeforesmtp commented out.
Had no problems whatsoever.
The engine is 1.9.0

Hi guys
It is a week that I try to use action mail 1.9.0 (using openhabian), but it never works.
In a first time I thought it was why I have a two factor authentication on gmail, so I changed the mail server, but in the log I find always the previous gmail server. I uninstalled action-mail, I deleted the mail.cfg, afterwards I edited the fresh mail.cfg, but it seems that the system does not read the new cfg. Change of the port/tls has no effect. Any help?



shutdown OH2, clear /var/lib/openhab2/cache & /var/lib/openhab2/tmp, start OH2
Also, remove /var/lib/openhab2/config/org/openhab/mail.config before restart to be sure
Fix your /etc/openhab2/services/mail.cfg as in example below:

hostname=smtp.gmail.com
port=587
username=someone@gmail.com
password=somepass
tls=true
ssl=false
popbeforesmtp=false

With mail.cfg fixed, OH2 will recreate /var/lib/openhab2/config/org/openhab/mail.config upon startup and repopulate tmp & cache folders

Please likely a stupid question, I am a very beginner, so must i scratch all the files in the directory?


thanks

Yes. It’s all recreated on a current state after restart of openHAB.

1 Like

Yes. Also the subdirectories. In both directories.

systemctl stop openhab2
rm -rf /var/lib/openhab2/tmp/*
rm -rf /var/lib/openhab2/cache/*
rm /var/lib/openhab2/config/org/openhab/mail.config
systemctl start openhab2
tail -f /var/log/openhab2/openhab.log -f /var/log/openhab2/events.log

careful with rm -rf ! :slight_smile: (better use rm -ri to see what you are deleting)

unfortunately I had already used rm -R cache (and tmp), now I cannot restart xxx:8080 and I realized that all the things and items has been deleted

Cache and temp don’t hold config data.
Hopefully you didn’t remove /var/lib/openhab2/ dir… (which includes jsondb folder)
Is this dir still there?

le directory are there,

but xxx:8080 does not work
and

did you systemctl start openhab2 ?
what does the log say after that?

re-create the tmp subdirectory. it seems that you removed it (you should have removed only its contents /*)

mkdir /var/lib/openhab2/tmp/
chown openhab:openhabian /var/lib/openhab2/tmp/

I created tmp
this is the status of openhab

ls -al /var/lib/openhab2/ please
it seems that the permissions are not correct for the tmp folder (can’t write the lock file)
did you change the ownership of the tmp folder after you created it?

(to avoid typing sudo all the time with the openhabian user, switch permanently to root using: sudo su)

I have used these rm commands also and now have :
FileNotFoundException: /var/lib/openhab2/cache/org.eclipse.osgi/185/0/.cp/lib/commons-email-1.4.jar

even after a re-start of OH2 and a cold reboot.

ls -la /var/lib/openhab2/cache only shows
drwxrwxr-x+ 4 openhab openhabian 4096 Oct 25 10:09 .
drwxrwxr-x+ 13 openhab openhabian 4096 Oct 14 17:27 …
-rw-rw-r-- 1 openhab openhab 38486 Oct 25 10:09 1508881579466.log
drwxrwxr-x+ 3 openhab openhabian 4096 Oct 25 00:03 org.eclipse.core.runtime
drwxrwxr-x+ 203 openhab openhabian 4096 Oct 25 09:44 org.eclipse.osgi

Is there a repair I can do or do I need to do a complete re-install?

You need to follow the steps from post # 11

When you will start up OH2 again, the service will re-populate the cache and tmp directories with the proper content and you will not have any problems.

If this doesn’t work, re-install the mail action from PaperUI.

Thanks for your reply but it seems the rm commands have broken my system way beyond that. I have followed the post #11 steps but still have issues.
The exec binding was broken but a re-install thru PaperUI fixed that.
The mqtt binding is not working after two re-installs thru PaperUI. I then tried uninstalling the mqtt binding and then re-starting OH2 before again re-installing. It is like mqtt is not installed looking at the logs. I will set logging to DEBUG and report further.
I did the same with the mail-action (Version 1.10.0) and using the gmail settings above. Not getting any response with a basic rule to test an email.
Thanks for any suggestions.