Help with sending emails

Help with sending emails

John Smith發表於
Number of replies: 15

Hi everyone!

I have installed moodle in my home web server but I can't configure it to send emails. I think I need to leave blank all fields in config tab so I can send emails with PHP.

This is the errot tha shows with debugging on:

Error calling message processor email

  • line 127 of /lib/classes/message/manager.php: call to debugging()
  • line 88 of /lib/classes/message/manager.php: call to core\message\manager::send_message_to_processors()
  • line 229 of /lib/messagelib.php: call to core\message\manager::send_message()
  • line 2219 of /message/lib.php: call to message_send()
  • line 33 of /admin/user/user_bulk_message.php: call to message_post_message()

I have already try configuring Gmail but no email sent either.

Can someone please help me? I need to send email to students, blogs, forums, etc.

Thanks in advance.

Regards.

OS: Ubuntu 14.04.3 LTS trusty

PHP: 5.5.9

MySQL: 14.14

Apache: 2.4.7

Moodle: 2.9.2+ (Build 20151008)

評比平均分數: -
In reply to John Smith

Re: Help with sending emails

Visvanath Ratnaweera發表於
Particularly helpful Moodlers的相片 Translators的相片
In the case of default local SMTP ("blank all fields in config tab") do you have a SMTP service running in the computer? If so, a telnet session to port 25 should go like this:
$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mybuntu.localdomain ESMTP Postfix (Debian/GNU)
EHLO foo.bar.com
250-mybuntu.localdomain
[...]
mail from: nobody@example.com
250 2.1.0 Ok
rcpt to: atest@mail.addres
250 2.1.5 Ok
data
354 End data with .
Hi there!
.
250 2.0.0 Ok: queued as 008523800A7
quit
221 2.0.0 Bye
Connection closed by foreign host.
In reply to Visvanath Ratnaweera

Re: Help with sending emails

John Smith發表於

I seem it is not configured.

telnet localhost 25

Trying ::1...

Trying 127.0.0.1...

telnet: Unable to connect to remote host: Connection refused

In reply to Visvanath Ratnaweera

Re: Help with sending emails

John Smith發表於

If it helps, I attach netstat output.

附件 netstat.JPG
In reply to John Smith

Re: Help with sending emails

Visvanath Ratnaweera發表於
Particularly helpful Moodlers的相片 Translators的相片
Obviously you don't have a SMTP service running. The first is to decide whether you want to send mails through the local SMTP service (default) or you would take an external SMTP service, you mentioned Gmail in you first post. Read, for example, "EMail: php vs SMTP" https://moodle.org/mod/forum/discuss.php?d=321390.

Only if you decide for local SMTP install a SMTP server of your choice: Sendmail, Exim, Postfix, ... Linux has it all!

With Postfix, for example, you might need only:
- https://help.ubuntu.com/community/Postfix#Installation and
- the first 10 points of https://help.ubuntu.com/community/Postfix#Configuration.
評比平均分數:Useful (1)
In reply to Visvanath Ratnaweera

Re: Help with sending emails

John Smith發表於

I will try to install it. I hope I can be able to run it in the same web server I have moodle installed.

But my original question is about sending emails through PHP built-in feature that moodle provides. I don´t know why it doesn´t work. Any ideas?

Thanks for your help.

Regards.

In reply to John Smith

Re: Help with sending emails

Emma Richardson發表於
Documentation writers的相片 Particularly helpful Moodlers的相片 Plugin developers的相片

Do you have Cron running - that is what primarily prompts the emails to be sent...

Also, you still need to have an email service on your local server to use the php mail.

In reply to John Smith

Re: Help with sending emails

Ken Task發表於
Particularly helpful Moodlers的相片

'why it doesn't work' ... Moodle isn't a MTA it uses a PHP plugin for sending mail and as long as that plugin can process it to send it will attempt.  As far as Moodle errors etc. Moodle thinks it's been successful.   The only way to see, normally, is via server logs ... apache error log, messages log, maillog log if on LInux.

Due to the nature of SPAM and everyone's dislike of same, receiving mail servers are normally the culprits.   Example: when Internet was 'young' systems like AOL and Hotmail became spammer havens - get an AOL account via CD install (trial account), do your massive SPAM, never use the account again ... remove app from computer.   Begin entire process again, etc..   As a result, systems like AOL had to become more militant about EMail.   Same was/is true of systems like hotmail.

More than likely your Moodle server doesn't have DNS records for MX, SPF, nor DKIM ... all of which ID's a server as being a valid non-spamming server that sends mail.   That's why the recommendation is to use an SMTP server ... it's a true Mail server and those servers normally have MX, SPF, DKIM, etc. type records in DNS.

So it's not that the PHPMailer routine actually fails ... it really doesn't ... it's more a matter of how militant the receiving mail servers are.   Support a corp Moodle whose outsourced IT department refuses to setup an SMTP relay for a Moodle hosted within their domains (server is on RackSpace but it's FQDN is from the DNS server supported by the outsourced IT department).  Their reason given any question/request ... 'it's a server we don't support' ....  Ok, that's my problem, but it illustrates that the sending of Mail from any Apache application depends upon other factors beyond Apache and the web application itself ...   Apache and the web application, in this case, Moodle (but it could be a WordPress or a Joomla or a X).

Sorry for the 'techiness' of response ... but you asked!!! ;)

'spirit of sharing', Ken

評比平均分數:Useful (3)
In reply to Ken Task

Re: Help with sending emails

John Smith發表於

Ok. I will install postfix, I think it is easy with the documentation.

The thing is I don't know anything about it. Now I am testing this web server with my dynamic public ip so I use NOIP. This page provides me the domain example.ddns.net.

Do you think I might be able to install it? Any special requirement I need? What about DNS, FQDN, etc?

If everything works I will buy my own domain but I will keep my dynamic ip.

Thanks.

Regards.

In reply to John Smith

Re: Help with sending emails

Ken Task發表於
Particularly helpful Moodlers的相片

Using dynamic IP address could be tricky when it comes to having the FQDN chosen to use with Moodle having 'valid' MX,SPF, DKIM, etc. records in DNS.   Might check into the dynamic service to see if they offer SMTP servers through which you can relay Moodle mail.   Keep in mind that all your really need is the ability to *send* from Moodle ... not receive.   Don't think you desire to get off into administration/protection of a Mail server as well as Moodle/Apache/MySQL.

'spirit of sharing', Ken

In reply to John Smith

Re: Help with sending emails

Visvanath Ratnaweera發表於
Particularly helpful Moodlers的相片 Translators的相片
You wrote:
> I will try to install it.

Why only _try_? On Linux, spec. on Ubuntu, it is a child's play. Did you check the Ubuntu documentation I have linked to?

> I hope I can be able to run it in the same web server I have moodle installed.

That is what I mean, when I say "to send mails through the local SMTP service".

>But my original question is about sending emails through PHP built-in feature that moodle provides.

Could you provide your sources?

> I don´t know why it doesn´t work. Any ideas?

Perhaps because there is no such _it_. For details see Ken's answer.

Also read the section on spam problem in sending mail from a random home box.
In reply to Visvanath Ratnaweera

Re: Help with sending emails

John Smith發表於

I told you I will try because I'm not an expert. I will follow the documentation you provided me.

And about the same web server, I told that because of the resources it needs to process both services.

Thanks.

Regards.

In reply to John Smith

Re: Help with sending emails

Paul Verrall發表於

Hi John,

IMO installing postfix will do nothing for you other than add unnecessary complexity to your setup. You do not need an SMTP/MTA server running locally if your Moodle is only going to be sending email (lets ignore for now that moodle can receive emails too...). PHP can send emails just fine without it.

You're problem, as Ken discussed, is probably that that your home webserver looks really spammy to other receiving MTA. This is what I believe are you best options to explore...

First make sure your moodle is sending emails as a real rotatable domain, nothing says spam like a fake sender address., see,

Site administration > Server > Support contact > Support email

and

Site administration > Plugins > Message outputs > Email > No-reply address

Then either....

1) Use an upstream SMTP server to relay your mail. A lot of ISP's will provide this functionality for you and you just need to add the appropriate details into moodle (Site administration > Plugins > Message outputs > Email). Depending on the service your ISP provides you may need to ensure moodle is sending as a valid email address (see above).

If you have set this up and it is still not working, enable SMTP debugging,

Site administration > Development > Debugging > Debug email sending

And then try a 'forgotten password' process from your login pages, you should see the full output on the SMTP conversation with with the upstream SMTP relay server which will usually tell you exactly what happened. Also check the moodle logs in,

Site administration > Reports > Logs

And set the activities column to 'site errors'


2) Make your home server look like a real SMTP server. Ken mentioned SPF, DKIM etc... That is great, but advanced, forget it for now. The most important thing to do is ensure your global IPs forward and reverse DNS are the same. Now this might not be possible if you are on a 'home' DSL type connection and are NAT-ING your servers IP address... If this is the case go back to option (1) as this is never going to work well for you with either PHP Mailer or Postfix. 

評比平均分數:Useful (1)
In reply to Paul Verrall

Re: Help with sending emails

John Smith發表於

Thanks, I will check with my ISP provider for a SMTP server.

Anyway, I succesfully managed to configure postfix to send emails outside my network. The thing is, as mentioned before, all destinations accounts like hotmail, gmail or even the account for the company I work for, are blocking my emails. In /var/log/mail.log I see all messages.

As I am a bit stubborn, I ask all of you whether there is a method for not blocking emails. You mentioned before SPD, DKIM, etc. Is it posible to make it work (for free)? Any tutorial to follow on?

Thanks.

In reply to John Smith

Re: Help with sending emails

Ken Task發表於
Particularly helpful Moodlers的相片

You can be as stubborn as you like, but there comes a point where it's best to 'go with the flow'.

Don't think I've ever seen any dynamic DNS system also offer dynamic setups for EMail.   Spammers would love that!

Installing Postfix enabled you to see things more easily (and you could use alpine in conjunction with Postfix to test sending to various SMTP servers), but that's about as far as you can take that ... other than configuring it to forward all non-local Email to a 'smarthost' - or SMTP server that has the appropriate MX, SPF, DKIM or whatever records in DNS to validate the sending machine as being a valid mail server.

Final 2 cents. 微笑

'spirit of sharing', Ken


評比平均分數:Useful (1)