WP to Mail

Hi
I am using 4D version 17.4.

I have made Write Pro invoices by code in 4D. This is used for bulk mailing of membership fees for volunteers. But I can not find any method to get this invoices into the mail. Best solution will be an (pdf) attachment, but a solution where the document is included in the email as HTML may also be acceptet.

Bjørn Arve Iversen
Zoft Zircus AS

While it is more easy with v18 (https://blog.4d.com/easily-send-a-4d-write-pro-document-containing-images-as-the-body-of-an-email/) you still can do it with v17…

Export your 4D Write Pro document using:
WP EXPORT VARIABLE(WParea;$mime;wk mime html)

Then use 4D Internet Command to send your email as html:
https://doc.4d.com/4Dv17/4D/17/SMTP-QuickSend.301-3785447.en.html
(see example 4).

To use a PDF export, you need to print the 4D Write Pro document as PDF.
Then create an email with the created PDF as enclosure.

To print as PDF on Windows see:
https://doc.4d.com/4Dv17/4D/17.4/Integration-of-PDFCreator-driver-under-Windows.300-4883295.en.html
(scroll to Windows 10, ignore PDFCreator)

For Mac see:
https://doc.4d.com/4Dv17/4D/17.4/SET-PRINT-OPTION.301-4883296.en.html
and follow “Destination option = 3/PDF”

Hi and thanks
I will try your solutions.

Unfortunately, I do not have the opportunity to update to version 18. It was tough enough to upgrade to version 17. (Pensioner who works for free for voluntary organizations).

But it seems like version 17 will do the job just fine.

Hi again
I have now tried the WP Export Variable solution. It almost worked.

This is the printed Write Pro document:

scan.pdf (316.2 KB)

… and this is from e-mail:

As you can see the tabulator do not display correctly in the last image (the mail).

I will also try the pdf solution (which is better). I have tried it before but it did not work on Mac.

From my experience, I can confirm that you can send email in v17 with a PDF join (from a 4D Write document) it works (on Mac and PC !). But, the body part of the mail can use rich text (coming from 4D Write Pro) but only rich text not for having HTML exactly as the printing document.
You should include the PDF and use the body only for having rich text BUT not try to have the document directly in the body.

OK
I will try the pdf solution.

It worked on Mac. I tried this solution earlier, but I got a privilage error. Tried to use desktop as the cache for pdf until sending. This time I used the 4D folder (Get 4D folder - command).

The code do the folloving:

  1. Get invoice info
  2. Make Write Pro document
  3. Export PDF to disk
  4. Make mail
  5. Attach PDF
  6. Send mail
  7. Delete PDF
  8. Next invoice

Is it OK to use 4D folder — even when I run with Engine?

You should use a specific folder which have read-write access all the time.
It can be the special hidden temp folder for each OS but it also depend of the selected setting you choice in 4D settings. Or use a folder that you are sure that is accessible all the time.
The problem can also be the name of the (cache) PDF file you generate (a good solution can be to use a subfolder where you empty each time to be sure you can use the name you want).

Since I do not know the folder settings used by the different organisations (customers) I thought the 4D folder always was read/write for the 4D app. I also thought that desktop always was read/write, but I was obviously wrong. May be I can add a subfolder in the datafolder (where I put the .4dd file).

Thanks for all help. I hope I will make it from here.

Hi
Your solution for Mac works very fine, but I am not able to make the Windows variant work as supposed.

Here is my code (approximately):

$Filename:="MEMFakt "+String([Bills]No)+".pdf"
txtPath_to_file:=$Folder+$Filename 

// NOTE
// $Folder is — C:\\Users\\baiversen\\Desktop\\Members 2020.04\\Members 2020.04\\Members data\\Temporary files\\
// txtPath_to_file is — C:\\Users\\baiversen\\Desktop\\Members 2020.04\\Members 2020.04\\Members data\\Temporary files\\MEMFakt 1439.pdf

If (<>long_Platform=Windows) 
    $PDFprinterWindows:="Microsoft Print to PDF" 
   PRINTERS LIST($Printers) 
   If (Find in array($Printers;$PDFprinterWindows)>0) // The printer is found
       SET CURRENT PRINTER($PDFprinterWindows) 
       SET PRINT OPTION(Destination option;2; txtPath_to_file) 
       WP PRINT(wpBill;0) // The error line
   Else  
        Trace 
   End if  
Else  
    //Mac method is working
End if

The error is in the WP Print line (unknown error).

Can you see the cause of error?

Bjørn Arve

Perhaps with :

SET CURRENT PRINTER(Generic PDF driver)

Hello and thanks for respond
According to this description: https://doc.4d.com/4Dv17/4D/17.4/Integration-of-PDFCreator-driver-under-Windows.300-4883295.en.html

I think that the command you are suggesting is a pre-Windows 10 solution. I will try, of cause, but since the “Microsoft Print to PDF” is found in the printerlist I do not think that is the problem.

I am running 4D with Windows using Parallells virtual machine (Mac). Can that be a problem?

What contain this variable ? are you sure that you have the right to write in this path ?

Thanks for answering
txtPath_to_file = C:\\Users\baiversen\\Desktop\\Members 2020.04\\Members 2020.04\\Members data\\Temporary files\\MEMFakt 1439.pdf

Regarding rights. I save in Temporary Files within the folder I use for data. Sinse the database is functioning I do know that the folder «Members data» is in read/write.

I will check anyway.

I have now checked as good as I can about write protection of this folder. But I am not a Windows user.

When I check the folders properties (attributes) on Desktop it is marked as Write protected. I can remove the mark, but still — if I check again — it is Write protected.

Since I thought this was strange i made this code up front of the Write Pro code:

C_TIME($Document)
$Document:=Create document("Test.txt") ` Create new document Test.txt
If(OK=1)
  SEND PACKET($Document;"Testing Members") ` Write in document
  CLOSE DOCUMENT($Document) ` Closing
End if

… and this document was saved with the sent text “Testing Members”.

So I suppose the folder is not Write protected.

Just test your code with a simple path like in your “Documents” folder.

Hi this solution works. I guess the problem is that I am running Windows on a virtual machine (Parallells). When I ask for printerlist I get the Windows printers and the “Microsoft Print to PDF” are found. When I actually print, the Mac drivers are used and there are no printers with tis name.

Anyway it works. Thanks a lot.

1 Like

I was to quick saying “this solution works”. It almost works. The pdf file is saved, sent and deleted. Exact as wanted. BUT the pdf-file can not be opened. Not before sending and not after sending. Not on Windows and not on Mac.

I will now try to re-install the “Microsoft Print to PDF” and see if that helps.

I have also tried “PDF Pro Virtual Printer”. The result PDF-file can not be opened.