Email setup gmail: Difference between revisions

From MoodleDocs
m (→‎See also: Added a reference about keeping root CA certificates up-to-date)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Google's mail servers can be set up as the SMTP server for Moodle, although in many cases may not be suitable for a production system (see first heading below).
Google's mail servers can be set up as the SMTP server for Moodle, although in many cases may not be suitable for a production system (see first heading below).


Setting it up will require a hack to the code.
 


== Is Google mail suitable for your requirements? ==
== Is Google mail suitable for your requirements? ==
Google mail has a couple of limitations which make it unsuitable for many Moodle installs, please check the following two points before continuing.
 
Before spending any time trying to get Gmail to work as your SMTP server, please read the following two points carefully and make sure you understand the limitations. It is also worth reading [https://moodle.org/mod/forum/discuss.php?d=65156&parent=988492 this forum post] which suggests what is probably a more suitable solution.
 
Google mail has a couple of limitations which make it unsuitable for many Moodle installs. Please check the following two points before continuing.
# '''No support for multiple "From" addresses.''' When sending emails, Moodle attempts to send them "From" the email address of the user writing the message, this allows the recipient to reply directly to the sender via email. Google, both in their Gmail and Apps for Education product do not allow this - so any emails sent from the system will be from the account you use to authenticate on the SMTP server. To make things more confusing, the name will be the recipients, but the email address will be the SMTP account's email address, for example: "Dr Fred Bloggs" <moodlemail@mycollege.edu>. If you wanted to use Gmail's SMTP regardless, you would be advised to use a dedicated account for the purpose, and have an auto response so that messages to the address bounce back with an instruction to click on the link in the email and reply through Moodle.
# '''No support for multiple "From" addresses.''' When sending emails, Moodle attempts to send them "From" the email address of the user writing the message, this allows the recipient to reply directly to the sender via email. Google, both in their Gmail and Apps for Education product do not allow this - so any emails sent from the system will be from the account you use to authenticate on the SMTP server. To make things more confusing, the name will be the recipients, but the email address will be the SMTP account's email address, for example: "Dr Fred Bloggs" <moodlemail@mycollege.edu>. If you wanted to use Gmail's SMTP regardless, you would be advised to use a dedicated account for the purpose, and have an auto response so that messages to the address bounce back with an instruction to click on the link in the email and reply through Moodle.
# '''Daily limit of 500 sent messages.''' There is a daily limit on any one google account of [http://googlesystem.blogspot.com/2008/06/gmails-limitations-for-sending-messages.html 500 individual email messages, or 2000 recipients across all emails]. Your account can get blocked if you go over this on a regular basis. If you have more than 500 users, it will only take one message to the front page news forum to exceed this quota.  
# '''Daily limit of 500 sent messages.''' There is a daily limit on any one google account of [http://googlesystem.blogspot.com/2008/06/gmails-limitations-for-sending-messages.html 500 individual email messages, or 2000 recipients across all emails]. Your account can get blocked if you go over this on a regular basis. If you have more than 500 users, it will only take one message to the front page news forum to exceed this quota.  


== GMail SMTP with Moodle 2.3  ==
== GMail SMTP with Moodle ==
 
Using Gmail's SMTP servers is a very straight forward process. First navigate to the following location:
Using Gmail's SMTP servers is a very straight forward process. First navigate to the following location:


Location: ''Settings > Site administration > Plugins > Message outputs > Email''
Location: ''Settings > Site administration > Plugins > Message outputs > Email''




Line 38: Line 38:
  Google will remember the application after it signs in, and will allow it to access your account in the future
  Google will remember the application after it signs in, and will allow it to access your account in the future
  as long as it uses the correct password.
  as long as it uses the correct password.


After you have done this, you will then be able to send emails through the Google SMTP server.
After you have done this, you will then be able to send emails through the Google SMTP server.
== Code Modification ==
''Please note:'' The following code modifications are ''not needed'' to allow GMail to be used with Moodle. All changes can be done through the interface, outlined above.
In your Moodle site go to <tt>/lib/phpmailer/</tt> and modify the following file:
=== class.smtp.php ===
Around line 83 DIRECTLY after the '''Connect''' function header, insert this line immediately after the "{" :
$host = 'ssl://' . $host;
Note: It appears that you can simply enter your host as ssl://smtp.gmail.com:465 to avoid the need for code changes.
== Code Modification (1.9.2 or lower) ==
These two additional modifications need to be made in 1.9.2 or lower as the '''SMTP hosts''' setting above will not allow the port to be included.
=== class.phpmailer.php ===
around line 162
*Change <tt>var $Port = 25;</tt> to <tt>var $Port = 465;</tt>
=== class.smtp.php ===
around line 30
*Change <tt>var $SMTP_PORT = 25;</tt> to <tt>var $SMTP_PORT = 465;</tt>
== Tips and tricks ==
* Some sites may need the additional step of un-commenting the '''php_openssl.dll''' extension in <tt>php.ini</tt>.
===Google education edition with 1.9.9===
When using Google Education Edition with 1.99
The latest php mailer is paramont. If someschool.edu email at google is not accepting mails from the moodle as valid mails you need to create an SPF record at your host, allowing mail from the Central Mail server, Google and the local server which satisified Google's validation desires.
@ 14400 IN TXT "v=spf1 ip4:174.121.161.XXX
include:aspmx.googlemail.com mx:c1.hostname.com ~all"
This bit is server side more than moodle so if you are on managed or shared hosting the server admin will have to do the record (try submitting a request to have the record added with full details of how and why to do so) then follow the previous the directions in this record.


== See also==
== See also==


*Email settings in [[Messaging settings]]
*Email settings in [[Messaging settings]]
* Root CA certificates should be up-to-date [https://moodle.org/mod/forum/discuss.php?d=366514#p1478917 to avoid connections issues]


[[ja:GmailでのEメール設定]]
[[ja:GmailでのEメール設定]]

Latest revision as of 23:23, 7 March 2018

Google's mail servers can be set up as the SMTP server for Moodle, although in many cases may not be suitable for a production system (see first heading below).


Is Google mail suitable for your requirements?

Before spending any time trying to get Gmail to work as your SMTP server, please read the following two points carefully and make sure you understand the limitations. It is also worth reading this forum post which suggests what is probably a more suitable solution.

Google mail has a couple of limitations which make it unsuitable for many Moodle installs. Please check the following two points before continuing.

  1. No support for multiple "From" addresses. When sending emails, Moodle attempts to send them "From" the email address of the user writing the message, this allows the recipient to reply directly to the sender via email. Google, both in their Gmail and Apps for Education product do not allow this - so any emails sent from the system will be from the account you use to authenticate on the SMTP server. To make things more confusing, the name will be the recipients, but the email address will be the SMTP account's email address, for example: "Dr Fred Bloggs" <moodlemail@mycollege.edu>. If you wanted to use Gmail's SMTP regardless, you would be advised to use a dedicated account for the purpose, and have an auto response so that messages to the address bounce back with an instruction to click on the link in the email and reply through Moodle.
  2. Daily limit of 500 sent messages. There is a daily limit on any one google account of 500 individual email messages, or 2000 recipients across all emails. Your account can get blocked if you go over this on a regular basis. If you have more than 500 users, it will only take one message to the front page news forum to exceed this quota.

GMail SMTP with Moodle

Using Gmail's SMTP servers is a very straight forward process. First navigate to the following location:

Location: Settings > Site administration > Plugins > Message outputs > Email


To get the SMTP servers functioning, only four values need to be set:

SMTP hosts: smtp.gmail.com:465 NOTE: Leave out the port (:465) in 1.9.2 or lower

SMTP security: SSL

SMTP username: Your email address @gmail.com or your own domain if using Google Apps

SMTP password: password for the above email account


You may get an email from Gmail saying that an external application is trying to access your account and Google will actually prevent this login process from succeeding.

To prevent this from happening, log into your gmail.com account and then visit: https://accounts.google.com/DisplayUnlockCaptcha

And you will then see the following message:

Sign in using the application you want to authorize access to your account within the next ten minutes.
Google will remember the application after it signs in, and will allow it to access your account in the future
as long as it uses the correct password.

After you have done this, you will then be able to send emails through the Google SMTP server.

See also