Recent

Author Topic: Email sending  (Read 5787 times)

anis2505

  • Full Member
  • ***
  • Posts: 201
Email sending
« on: December 17, 2012, 01:39:45 pm »
Hi,

I was thinking does anyone successfully managed to send an email via a lazarus application using Synapse LNet or anything else.
I've tried both and no chance.
If so please tell me how????

regards
Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

BeniBela

  • Hero Member
  • *****
  • Posts: 763
    • homepage
Re: Email sending
« Reply #1 on: December 17, 2012, 01:59:07 pm »
SendToEx does it very well.

Here is an old console program, where I use it:

Code: [Select]
var from, receiver,subject,line: string;
    sl: TStringList;
    i: Integer;
begin
  from := 'default sender @ somewhere';
  receiver:= 'default receiver @ somewhere';
  for i:=1 to Paramcount do
    if ParamStr(i) = '--from' then from := ParamStr(i+1)
    else if ParamStr(i) = '--to' then receiver:= ParamStr(i+1)
    else if ParamStr(i) = '--subject' then subject:= ParamStr(i+1);
  sl:= TStringList.Create;
  while not eof(Input) do begin
    ReadLn(line);
    sl.Add(Utf8ToAnsi(line));
  end;

  SendToEx(from,receiver,'=?utf-8?B?'+ EncodeBase64(subject)+ '?=','<your smtp server>',sl,'<your username>','<your password>');
end.

anis2505

  • Full Member
  • ***
  • Posts: 201
Re: Email sending
« Reply #2 on: December 17, 2012, 02:18:08 pm »
SendToEx does it very well.

Here is an old console program, where I use it:

Code: [Select]
var from, receiver,subject,line: string;
    sl: TStringList;
    i: Integer;
begin
  from := 'default sender @ somewhere';
  receiver:= 'default receiver @ somewhere';
  for i:=1 to Paramcount do
    if ParamStr(i) = '--from' then from := ParamStr(i+1)
    else if ParamStr(i) = '--to' then receiver:= ParamStr(i+1)
    else if ParamStr(i) = '--subject' then subject:= ParamStr(i+1);
  sl:= TStringList.Create;
  while not eof(Input) do begin
    ReadLn(line);
    sl.Add(Utf8ToAnsi(line));
  end;

  SendToEx(from,receiver,'=?utf-8?B?'+ EncodeBase64(subject)+ '?=','<your smtp server>',sl,'<your username>','<your password>');
end.

Thanks.

A stupid question  :-[ . what library should I include to get SendToEx
Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: Email sending
« Reply #3 on: December 17, 2012, 02:24:50 pm »
A stupid question  :-[ . what library should I include to get SendToEx

Unit smtpsend of Synapse

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Email sending
« Reply #4 on: December 17, 2012, 02:32:41 pm »
SendToEx does it very well.

Here is an old console program, where I use it:

Code: [Select]
var from, receiver,subject,line: string;
    sl: TStringList;
    i: Integer;
begin
  from := 'default sender @ somewhere';
  receiver:= 'default receiver @ somewhere';
  for i:=1 to Paramcount do
    if ParamStr(i) = '--from' then from := ParamStr(i+1)
    else if ParamStr(i) = '--to' then receiver:= ParamStr(i+1)
    else if ParamStr(i) = '--subject' then subject:= ParamStr(i+1);
  sl:= TStringList.Create;
  while not eof(Input) do begin
    ReadLn(line);
    sl.Add(Utf8ToAnsi(line));
  end;

  SendToEx(from,receiver,'=?utf-8?B?'+ EncodeBase64(subject)+ '?=','<your smtp server>',sl,'<your username>','<your password>');
end.
Thanks you guys, took the liberty of updating
http://wiki.lazarus.freepascal.org/Synapse#Sending_email

additions/updates (TLS connections??!!) more than welcome
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

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Email sending
« Reply #5 on: December 18, 2012, 12:53:04 pm »
SendToEx does it very well.
SendToRaw() is even more simple (plain text email).

Code: [Select]
uses smtpsend (Synapse);

aSL:=TStringList.Create;
try
  aSL.Add('From: '+aSender);
  aSL.Add('To: ' + aReceiver);
  aSL.Add('Date: ' + Rfc822DateTime(now));
  aSL.Add('Subject: '+aSubject);
  aSL.Add('');
  aSL.Add(aMessage);
  if not SendToRaw(aSender, aReceiver, 'localhost', aSL, '', '') then
    writeln('Failed to send email');
finally
  aSL.Free;
end;
« Last Edit: December 18, 2012, 12:54:42 pm by Ocye »
Lazarus 1.7 (SVN) FPC 3.0.0

 

TinyPortal © 2005-2018