MSMTP: usare GMail con la funzione mail() in PHP

Questo articolo può essere applicato a differenti scenari: una installazione Linux minimale, un’istanza virtuale o contenitore che non include un MTA, incompatibilità tra differenti interpreti, un desolante messaggio nella riga di comando da console tipo

sh: 1: /usr/sbin/sendmail: not found

In aggiunta, si può avere la necessità (anche dal punto di vista della comodità o per via di esigenze legate a razionalizzazione delle risorse) di voler utilizzare un servizio esterno all’host che si occupi dell’inoltro dei messaggi di posta elettronica, sfruttando un servizio SMTP con un profilo esistente (fornito anche all’esterno della sede locale, come per es. Google Apps for Work‎ od il comune Gmail), escludendo l’opzione di installare un servizio puro superfluo o inutile su una macchina non desinata a ricevere posta.

Sintesi: il software in questione deve occuparsi di smistare messaggi di posta elettronica, rappresentando il tratto di unione tra un interpretesendmail-compatibile ed un client SMTP. Esiste di già, ed è MSMTP.

MSMTP: requisiti ed installazione

Il progetto MSMTP manutenuto da Martin Lambers è rilasciato come codice libero in licenza GPLv3: i requisiti sono ristretti ad un compilatore e le funzioni per socket tipo Berkeley. Disponibile sui repository delle maggiori distribuzioni Linux, si può comunemente lanciare

apt-get install msmtp

per l’installazione in Debian od Ubuntu, mentre per le altre in base yum tipo RHEL / CentOS

yum install msmtp

Su Apple MacOS 10, MSMTP è disponibile con la formula homebrew

brew install msmtp

La configurazione si basa su file di testo semplici, con i percorsi predefiniti per sistema su /etc/msmtprc e ~/.msmtprc per le configurazione dei singoli utenti. Sul sito di riferimento è presente la documentazione completa (in inglese) ed un file di esempio. Davvero lineare.

google-gmail

Integrazione con PHP ed uso di account Gmail

Come riportato poco prima, MSMTP è sostituibile al comando sendmail, pertanto ci si può disporre a questo tipo di configurazione creando un file in /etc/msmtprc con la configurazione di un account SMTP esistente; il software supporta il TLS, quindi l’esempio Gmail è anche un buon esercizio per verificare questa opzione.

Contenuto del file /etc/msmtprc :

# Esempio msmtprc per Gmail
# 2014 Alessio Felicioni
# fonte: http://www.alessiofelicioni.it/msmtp-gmail-funzione-mail-php/

# valori predefiniti
defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /var/log/msmtp.log

# configurazione account
account default
host smtp.gmail.com
port 587
auth on
from utente@gmail.com
user utente@gmail.com
password La(TUA)Password_va_qui

Importante garantire che il file sia leggibile dall’utente che esegue il php via processo server (es. apache, www-data o equivalente): vale a dirsi

chown www-data /etc/msmtprc
chmod 600 /etc/msmtprc

Quindi il valore di sendmail_path in php.ini potrebbe essere sostituito con la seguente sintassi

sendmail_path = "/usr/bin/msmtp -C /etc/msmtprc -t"

MSMTP supporta anche la configurazione di account multipli anche sullo stesso file: il parametro che controlla questa opzione è -a con il significato che se invocato con valori differenti, lo smistamento avverrà attraverso profili (ed eventualmente tratte/server SMTP) differenti.

La sezione di documentazione del progetto all’indirizzo http://msmtp.sourceforge.net/documentation.html è il punto di riferimento per utilizzare al meglio il programma e ricca di esempi.

63 pensieri su “MSMTP: usare GMail con la funzione mail() in PHP”

  1. Hi I am so excited I found your blog page, I
    really found you by error, while I was searching on Askjeeve
    for something else, Anyhow I am here now and would just like to say many thanks for a tremendous post and
    a all round entertaining blog (I also love the theme/design),
    I don’t have time to look over it all at the moment but I have book-marked it and also included your RSS feeds,
    so when I have time I will be back to read a great deal more, Please do keep
    up the excellent job.

  2. Excellent post. I was checking continuously this blog and I am
    inspired! Extremely helpful information specifically the closing phase :
    ) I handle such information a lot. I was looking for this particular information for a very long
    time. Thank you and best of luck.

  3. obviously like your web site but you have to take a look at the
    spelling on quite a few of your posts. Many of them are rife
    with spelling problems and I find it very troublesome to
    inform the truth then again I will certainly come back again.

  4. wonderful publish, very informative. I ponder why one other experts on this sector
    don’t realize this. You must continue your writing.
    I am confident, you’ve a massive readers’ base already!

  5. Thank you for the good writeup. It in truth was a amusement account it.
    Glance complicated to far delivered agreeable from you!
    However, how can we communicate?

  6. These are typically genuinely great ideas in about blogging.

    You may have touched some nice things here. In any manner keep up wrinting.

  7. Attractive section of content. I simply stumbled upon your blog and in accession capital to say that I
    acquire actually enjoyed account your weblog posts.
    Anyway I’ll be subscribing on your augment and even I success you get right of entry to constantly rapidly.

  8. Hi it’s me, I am also visiting this web site daily,
    this site is truly fastidious and the people are truly
    sharing pleasant thoughts.

  9. Howdy could you mind letting me know which hosting company you’re utilizing?
    I’ve loaded your site in 3 different internet browsers and
    I have to admit this blog loads a good deal quicker then most.
    Is it possible to recommend an excellent hosting provider with a fair price?
    Thank you, I appreciate it!

  10. Excellent post however , I was wondering if you could write a litte more on this topic?
    I’d be very grateful if you could elaborate a little bit more.
    Appreciate it!

  11. great points altogether, you simply won a brand new reader.

    What could you recommend about your post that you just made a few days ago?

    Any positive?

  12. Greate pieces. Keep writing such kind of info on your page.
    Im really impressed by your blog.
    Hi there, You’ve done an excellent job. I will certainly digg it and in my view suggest to my friends.
    I am sure they’ll be benefited from this site.

  13. I do believe the admin of the website is actually making an effort in favor of his site, as here every material
    is quality based stuff.

  14. I feel that is one of the most significant info
    for me. And i’m satisfied studying your article. However want to observation on few general things, The website style is perfect, the articles is
    really nice : D. Excellent process, cheers

  15. Thanks for that marvelous posting! I definitely enjoyed reading it, you might be
    a fantastic author. I am going to be sure you bookmark your blog and definately will often return down the line.
    I would like to encourage continue your great work, use a nice morning!

  16. Hmm is anyone else encountering problems with the images on this blog loading?

    I’m trying to figure out if its a problem on my end or if it’s the blog.

    Any feed-back would be greatly appreciated.

  17. I simply want to say I am just beginner to blogs and truly loved this web blog. Very likely I’m going to bookmark your blog post . You really come with really good well written articles. Thanks a lot for revealing your web site.

  18. Spot up with this write-up, I absolutely believe this phenomenal site needs significantly more attention. I’ll probably be returning to read more, thanks for the
    advice!

  19. Simply want to say your article is as amazing. The clarity to your publish is simply
    nice and that i can assume you are a professional on this
    subject. Fine along with your permission allow me to grab
    your RSS feed to stay up to date with imminent post.
    Thank you a million and please carry on the rewarding work.

  20. Hi there to all, how is the whole thing, I think every one is getting more from this website,
    and your views are good designed for new visitors.

  21. Wow that was unusual. I just wrote an really long comment but after
    I clicked submit my comment didn’t appear. Grrrr…
    well I’m not writing all that over again. Anyways,
    just wanted to say wonderful blog!

  22. Hi! I could have sworn I’ve visited this site before but after taking
    a look at a lot of the articles I realized it’s new to me.
    Regardless, I’m certainly pleased I came across it and
    I’ll be book-marking it and checking back frequently!

  23. each time i used to read smaller articles that as well
    clear their motive, and that is also happening with this paragraph which I am reading at this time.

  24. Thanks for ones marvelous posting! I truly enjoyed reading it, you will be a fantastic author.

    I will make sure to bookmark your site and definately will eventually come back in the foreseeable
    future. I would like to encourage one to continue your great writing, use a nice afternoon!

  25. Cіao un mio amіco mi ha girato l’indirizzo di questo bloog e sono ѵenuta a vedere сom’è.
    Mi ρiace enormemente. Meseso tra i preferiti. Bellissimo blog e grafica spettaсoloso!

  26. Admiring the hard work you put into your site and detailed information you offer.
    It’s awesome to come across a blog every once in a while that isn’t the same outdated rehashed information. Great read!
    I’ve bookmarked your site and I’m including your RSS feeds to my Google
    account.

  27. I like the helpful info you provide to your articles. I will bookmark your blog and test again right here regularly.
    I am fairly certain I will be informed plenty of new stuff
    proper right here! Good luck for the following!

  28. Thankfulness to my father who informed me about this blog, this website is
    in fact remarkable.

  29. Thanks for finally writing about >MSMTP: usare GMail con la funzione mail() in PHP – Alessio Felicioni <Liked it!

  30. Way cool! Some very valid points! I appreciate you writing this post and
    the rest of the site is also very good.

  31. What’s up i am kavin, its my first occasion to commenting anyplace, when i read this paragraph i thought i could
    also create comment due to this brilliant paragraph.

  32. It’s remarkable to pay a quick visit this web site and reading the views
    of all friends concerning this piece of writing, while I am also keen of getting experience.

  33. You should take part in a contest for one of the greatest websites on the internet.

    I most certainly will highly recommend this blog!

  34. Wow, awesome weblog format! How lengthy have you been blogging for?
    you make running a blog glance easy. The total look of your web site is wonderful,
    as well as the content!

  35. Great blog here! Also your website loads up very fast!
    What web host are you using? Can I get your affiliate link to your host?
    I wish my website loaded up as fast as yours lol

  36. This is really interesting, You are a very skilled blogger.
    I have joined your feed and look forward to seeking more of your
    wonderful post. Also, I’ve shared your website in my social networks!

  37. Hi! I could have sworn I’ve been to this blog before but after
    reading through some of the post I realized it’s new
    to me. Anyways, I’m definitely delighted I found it and I’ll be bookmarking
    and checking back often!

  38. save for the early-bird gang of media types clustered in the press box and a scattering of event staff down on the field.

  39. gible to face ArsenalGranit Xhaka returns to the starting eleven for the Premier League clash, but Debuchy has brought back in from the cold at the Emirates, having last played in the North London derby last November.

  40. The warning read:?“Cold northerly winds will bring frequent snow showers through Thursday and into Friday.

  41. I have read so many posts on the topic of the blogger lovers however this post is actually
    a good piece of writing, keep it up.

  42. Good day I am so thrilled I found your web site, I really found you by mistake, while
    I was searching on Bing for something else, Regardless I
    am here now and would just like to say kudos for a remarkable post and a all round thrilling blog (I
    also love the theme/design), I don’t have time to
    browse it all at the moment but I have saved it and also included your
    RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up
    the awesome job.

  43. It’s difficult to find experienced people about this
    topic, however, you seem like you know what you’re talking about!
    Thanks

  44. I’m gone to convey my little brother, that he should also pay a visit this website on regular basis to take updated
    from hottest information.

  45. I blog quite often and I seriously thank you for your content.
    This article has really peaked my interest. I’m going to
    book mark your blog and keep checking for new information about once a week.
    I subscribed to your RSS feed as well.

  46. My family every time say that I am killing my time
    here at web, however I know I am getting knowledge daily by reading thes pleasant
    articles or reviews.

  47. Hi there to every one, since I am really eager of reading this blog’s post to be updated daily.
    It includes fastidious information.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *