Topic: [Script] Send report document to E-mail

How to send report document to E-mail


script:

procedure Form1_bReport_OnAfterClick (Sender: string);
var
    sFile: string;
begin
    Form1.bReport.Enabled := False;
    Form1.bReport.Caption := 'Please wait...';

    sFile := Form1.frxPDFExport1.FileName;

    if FileExists(sFile) then
        if SendMail('smtp.gmail.com', 'yourmail@gmail.com', 'password', 465, 'Your name', 'recipient@yahoo.com', 'Subject', 'Message', sFile) then
            ShowMessage('Message sent');

    Form1.bReport.Enabled := True;
    Form1.bReport.Caption := 'Send PDF to e-mail ';
end;

begin
    Form1.frxPDFExport1.OpenAfterExport := False;  
end.



Download project:

Post's attachments

Attachment icon Report to E-mail.zip 5.92 kb, 1102 downloads since 2015-09-26 

Dmitry.

Re: [Script] Send report document to E-mail

thanks...but i get error say read timed out....when i click to send file to email. and in script when i put password email ...i get error.also

Re: [Script] Send report document to E-mail

I tested the example using gmail for sending email, check your login/password and smtp server.

Dmitry.

Re: [Script] Send report document to E-mail

Not Work !

" Connect  time out. "
I try gmail.com,hotmail not work or set config smtp server !

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: [Script] Send report document to E-mail

You should ask your administator about whether the port 465 is open or not.

Dmitry.

Re: [Script] Send report document to E-mail

@outlook @live @hotmail
It Work !
But Gmail not Work

For @outlook @live @hotmail Set
Outgoing (SMTP) Server

Server address: smtp-mail.outlook.com
Authentication: Yes
Encrypted Connection: TLS
User name: Your email address
Password: Your password

Display " Read time out" --- It ok Sended  to email but delay 10-15 second

Reference http://windows.microsoft.com/en-us/wind … e-from-app

My Visual Database : I Love You
Easy For Beginner Student For Me

7 (edited by timlitw 2016-11-15 16:43:06)

Re: [Script] Send report document to E-mail

not tested but for Gmail you need to enable the app password feature - google it
or

  • Visit your App passwords page. ...

  • At the bottom, click Select app and choose the app you're using.

  • Click Select device and choose the device you're using.

  • Select Generate.

  • Follow the instructions to enter the App password (the 16 character code in the yellow bar) on your device.

  • Select Done.

8 (edited by timlitw 2016-11-15 19:19:51)

Re: [Script] Send report document to E-mail

in the example above what does this line refer to - ie what do I need to put in my program

sFile := Form1.frxPDFExport1.FileName;

I get an error
---------------------------
Script error
---------------------------
Undeclared identifier: 'frxPDFExport1' at 10:35
---------------------------
OK   
---------------------------


my form is "Reports"
the button is "YesterdayReport"
the file name of the report is prod_to_repack.fr3
the report is a sql report

Re: [Script] Send report document to E-mail

timlitw wrote:

in the example above what does this line refer to - ie what do I need to put in my program

May be your general form have another name?
So you must use name of general form instead Form1


Also perhaps you have old version.

Dmitry.

10 (edited by timlitw 2016-11-16 13:41:58)

Re: [Script] Send report document to E-mail

the button to run the report is in my Reports form

procedure Reports_YesterdayReport_OnAfterClick (Sender: string);
var
    sFile: string;
begin
    Reports.YesterdayReport.Enabled := False;
    Reports.YesterdayReport.Caption := 'Please wait...';

    sFile := Reports.frxPDFExport1.FileName;

    if FileExists(sFile) then
        if SendMail('smtp.gmail.com', 'username@gmail.com', 'password', 465, 'name', 'to address', 'title', 'Message', sFile) then
           ShowMessage('Message sent');

    Reports.YesterdayReport.Enabled := True;
    Reports.YesterdayReport.Caption := 'Yesterdays activity ';

end;

begin
       Reports.YesterdayReport.OpenAfterExport := False;
end.

Re: [Script] Send report document to E-mail

ok, I changed it back to Form1 and it does work,

I incorrectly assumed it needed to refer to the form that was sendig the report.

Thanks!