Recent

Author Topic: Please i need help with xmailer demo  (Read 5789 times)

evat

  • New member
  • *
  • Posts: 9
Please i need help with xmailer demo
« on: May 23, 2016, 04:56:01 am »
I have Lazarus installed on windows 7. Tried to send mail using xmailer demo.
Got message "file not open. Press ok to ignore and risk data corruption.
The package xmailerpkg.lpk has compiled ok but it did not give me the option to install it. I added it to the project.

Thanks in advance for any help.


 
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var Mail:TSendMail;
  3. begin
  4.   Mail := TSendMail.Create;
  5.     try
  6.       try
  7.         // Mail
  8.         Mail.Sender := 'eu@yahoo.com.br';
  9.         Mail.Receivers.Add('somebody@uol.com.br');
  10.         Mail.Subject := 'Este é o assunto';
  11.         Mail.Message.Add('Esta é a mensagem.');
  12.         // SMTP
  13.         Mail.Smtp.UserName := 'eu@yahoo.com.br';
  14.         Mail.Smtp.Password := '#########';
  15.         Mail.Smtp.Host := 'smtp.mail.yahoo.com';
  16.         Mail.Attachments.LoadFromFile('myfile.txt');
  17.         Mail.Smtp.Port := '465';
  18.         Mail.Smtp.SSL := True;
  19.         Mail.Smtp.TLS := True;
  20.         Mail.Send;
  21.         Write('E-mail sent successfully!');
  22.       except
  23.         on E: Exception do
  24.           Write(E.Message);
  25.       end;
  26.     finally
  27.       Mail.Free ;
  28. end;
  29. end;
  30. end.            
« Last Edit: May 23, 2016, 05:50:19 am by evat »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Please i need help with xmailer demo
« Reply #1 on: May 23, 2016, 07:50:11 am »
Code: Pascal  [Select][+][-]
  1.         Mail.Attachments.LoadFromFile('myfile.txt');

Try to put the full path to myfile.txt
or put a copy of it in Lazarus folder

evat

  • New member
  • *
  • Posts: 9
Re: Please i need help with xmailer demo
« Reply #2 on: May 23, 2016, 06:13:03 pm »
Thanks for the reply, but this error message occurs even without file attachment. 
The code is working partially: the message (and the file attached) are sent, althought the error message is showed.
Since xmailer uses the synapse libraries, i  tried xmailer with the estable synapse and also with svn synapse.
I have another project in another folder which works fine using xmailer.
I do not see any diference between the two projects. Even the DLL libraries are the same version.

Thanks in advance for any help

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Please i need help with xmailer demo
« Reply #3 on: May 23, 2016, 06:56:59 pm »
Are you attaching one file named myfile.txt, if so then use: 
Code: Pascal  [Select][+][-]
  1. Mail.Attachments.Add('myfile.txt');

Attachments is a list of files to be attached. It is of type TStrings (TStringList in the constructor)

evat

  • New member
  • *
  • Posts: 9
Re: Please i need help with xmailer demo
« Reply #4 on: May 24, 2016, 03:21:13 pm »
Thanks for the reply. Many thanks for your attention.
I have changed  Mail.Attachments.LoadFromFile('myfile.txt'); to Mail.Attachments.Add('myfile.txt');
The  code sends the message with the attached file but the only message it shows is that in Atach3.
I think the problem is that  i do not know how to configure Lazarus in Tools ===>Options and i do not know how to configure the Project Options.
 In Attach1 i show how Lazarus is configured. In Attach2 i show how the project is configured. I hope you can help me in this part.
Thank you.
« Last Edit: May 24, 2016, 03:26:45 pm by evat »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Please i need help with xmailer demo
« Reply #5 on: May 24, 2016, 04:28:35 pm »
"File not open" message comes from using Write, as in:
Code: Pascal  [Select][+][-]
  1.       Write('E-mail sent successfully!');
  2.  

If you want to use Write then remove the check from "Win32 gui application" in
Project Options -
  Compiler Options -
    Config and Target

This will show the console screen (the black terminal screen).

As for the package configuration, which has nothing to do with this message, you need to add the package as a requirement in Project Inspector. You don't need to add its path as you did in Attach2.jpg.

evat

  • New member
  • *
  • Posts: 9
Re: Please i need help with xmailer demo (solved)
« Reply #6 on: May 24, 2016, 05:30:37 pm »
Many thanks for your help.
As you sugested, i  have changed the command write for the command showmessage.
The code is working fine now.

 

TinyPortal © 2005-2018