Topic: Can't email invoices

Hi,

  I loaded  FA 2.2.11 a few nights ago.  I'm still poking my way around.

One problem that I can't seem to find my way around is: I can't email invoices.  I keep getting

Sending document by email failed

I did some digging around here and see that AF uses the mail function in PHP.  I can't find any entries let along errors in either the mail log or the PHP log.  I'm using postfix and can send email from the command line.  As a test I got a short PHP mailing script

<?php
# The message
$message = "Line 1\nLine 2\nLine 3";
# Send
mail('my.email@mydomain.com', 'My Subject', $message);
?>

Which works fine.

What can I check next?

Thank You,

MPH

I'd rather have a bottle in front of me than a frontal lobotomy.

Re: Can't email invoices

Mails in FA are sent using emial class in reporting/includes/class.mail.inc. Make some tests on parameters passed to mail() in email::send() and finding  source of the problem should be easy. Probably this is due to invalid form of $mail parameter.
Janusz

3 (edited by mph 10/23/2010 07:47:13 pm)

Re: Can't email invoices

Addendum:

  After a little more research (Following your instructions) It appears to be a problem with the $this->email header.  I've changed the other 2 variables and it works fine.  Any other combination including the header fails.  I don't have time to dig any further at the moment, hopefully later this evening.

Regards,

MPH
-----------
Janusz,

  Thanks for the info.  Here are the parameters being passed to the mail command.  They all look normal to me.  But I've not programmed anything this involved before.

Some of it may not look quite right as I've removed any personal information, email addresses etc...  I did verify that the original values are correct and the file pointed to does exist.

These are the variables and their values after executing the $ret = mail($mail, $this->subject, "", $this->header); statement.

$mail = Company Name Removed <my_email@address.com>

  $this->email
    to = Company Name Removed <my_email@address.com>

    cc =

    bcc =

    attachment = ../company/0/pdf_files/Invoice11.pdf

    boundry = a5bc2dd9d48cdbf1c107d47cadbcd068

    header = From: My Company <my_email@address.com>
                     MIME-Version: 1.0
                     Content-Type: multipart/mixed; boundary=a5bc2dd9d48cdbf1c107d47cadbcd068

                     This is a multi-part message in MIME format
                     --a5bc2dd9d48cdbf1c107d47cadbcd068
                     Content-Type: text/plain; charset=ISO-8859-1
                     Content-Transfer-Encoding: 8bit

                     Dear Test Customer

                     Attached you will find  Invoice No. 11

                     Kindest regards

                     Administrator
                     My Company
                     My Address
                     My City
                     00000
                     my_email@address.com
                     000.000.0000
                     --a5bc2dd9d48cdbf1c107d47cadbcd068
                     Content-Type: application/pdf; name=Invoice11.pdf
                     Content-Transfer-Encoding: base64
                     Content-Disposition: attachment; filename=Invoice11.pdf
       
                     Removed uuencoded data.

                     --a5bc2dd9d48cdbf1c107d47cadbcd068--

    subject = Invoice No. 11

    body = Content-Type: text/plain; charset=ISO-8859-1
                Content-Transfer-Encoding: 8bit

                Dear Test Customer

                Attached you will find  Invoice No. 11

                Kindest regards

                Me :)
                My Company
                My Address
                My City
                00000
                my_email@address.com
                000.000.0000

   ret = false

Thanks,

MPH

I'd rather have a bottle in front of me than a frontal lobotomy.

Re: Can't email invoices

You have tested mail() function with clean email address, so try the same in FA: remove company name and brackets leaving just email address. The constraints in form of email address header  depends only on mailer setup and are outside of FA/PHP scope.

Janusz

Re: Can't email invoices

Janusz,

I've got it figured out!!! 

The suhosin security patch for PHP was blocking the emails before the ever got to postfix(My email server).  This would explain why I couldn't find any info in it's log files.  I didn't find it until I increased the debug level in the postfix config file.
from /var/log/messages:

Oct 24 20:12:02 myserver suhosin[4627]: ALERT - mail() - double newline in headers, possible injection, mail dropped (attacker '10.x.x.x', file '/home/user/workspace/frontaccounting/reporting/includes/class.mail.inc', line 138)

Rather than remove a security measure, I decided to "massage" the code a little.  I removed all of the double "\n"s that I could find in the header and it still was failing.  Once I separated the body from the header, I was getting the emails.  However, for some reason there were extra line feeds in the uuencoded data which rendered the attachment useless.  Adobe said it was corrupt or improperly decoded.  So, I changed the chunking to a length of 72(which really is moot, it just wants a value) and added a "\n" for the EOL, and it everything is working great!!
The \n may not be right since I haven't tested it on a windows box yet.  I would think it's okay because email is email.  Both Windows and Linux read the same email very close to the same.

Thank You for your help and pointing me in the right direction.

Regards,

MPH

I'd rather have a bottle in front of me than a frontal lobotomy.

Re: Can't email invoices

Would you like to provide the patch you have done as a contribution to FrontAccounting, to be included in next release?

Janusz

Re: Can't email invoices

Absolutely!

  It'll just take me a little longer.  It was late (for me) last night when I got it working.  I've yet to change where the text / html content types go in the header.  I should be able to do that fairly easily tonight. 

  I have used patches for my own stuff, but have never submitted one before.  Other than documenting what I've done and trying to keep the code as fluid as possible with the original style.  Are there any other requirements / guidelines I should / could use?

Regards,

MPH

I'd rather have a bottle in front of me than a frontal lobotomy.

Re: Can't email invoices

You can just send your edited files to contributions (email in the Announcement Forum). Please add your own comments.

Re: Can't email invoices

I have used patches for my own stuff, but have never submitted one before.  Other than documenting what I've done and trying to keep the code as fluid as possible with the original style.  Are there any other requirements / guidelines I should / could use?

No, i don't think so. You can send changed files, or patches against selected sources version. We always check the sources before submitting to CVS.

Thanks in advance MPH smile
Janusz

PS. I also use Suhoshin patch on PHP without any side effects, but I think it can depend on mail content.
J.

Re: Can't email invoices

Okay,

  What is it with me and emailing roll smile  I tried to send the modified file to contributions@frontaccounting.com

Mail Delivery Failure:

Arrival-Date: Tue, 26 Oct 2010 18:41:52 -0400

Last-Attempt-Date: Tue, 26 Oct 2010 18:41:52 -0400
Remote-MTA: dns; frontaccounting.com
Diagnostic-Code: smtp; 550 No Such User Here
Action: failed
Final-Recipient: rfc822; contributions@frontaccounting.com
Status: 5.0.0

I'd rather have a bottle in front of me than a frontal lobotomy.

Re: Can't email invoices

Sorry mph, the mailbox is in frontaccounting.net domain.
To avoid problems we will establish the mailbox also at *.com.

Janusz

Re: Can't email invoices

Hello!!
I have the same problem, I can't send invoices  "TAX INVOICE 1. Sending document by email failed. Email: xxx@xxx.xom"  I tried to do some of the things commented here but  I dont have any program knowledge.

Thanks in advance for your help!!

Re: Can't email invoices

By the way, I use 2.3.21 version.

Thanks again