Forum > Networking and Web Programming

Simplest networking library?

<< < (3/4) > >>

arneolav:
Yes, I'v been looking at it, but i had expected Mail Attachment built in into SmtpSend in Synapse....

BigChimp:
http://lmgtfy.com/?q=synapse+smtp+attachment
gives
http://synapse.ararat.cz/doku.php/public:howto:tmimepart

Good luck.

arneolav:
Thanx, then I'v implemented myself...                    Send e-mail SMTP with Attachment, using Synapse;

Using modified  smtpsend.pas   look above.


--- Code: ---unit smtpsend;
.
.
uses ....  mimemess, mimepart;

function SendAttach(const MailFrom, MailTo, Subject, SMTPHost: string;
  const MailData: TStrings; const Username, Password, TargetPort, AttachFile: string): Boolean;


implementation 
.
.
.
.

function SendAttach(const MailFrom, MailTo, Subject, SMTPHost: string;
  const MailData: TStrings; const Username, Password, TargetPort, AttachFile: string): Boolean;
var
  m:TMimemess;
  l:tstringlist;
  p: TMimepart;
begin
  m:=TMimemess.create;
  l:=tstringlist.create;
  try

   {
    p := m.AddPartMultipart('mixed', nil);
    l.loadfromfile('c:\search.log');
    m.AddPartText(l,p);
    m.AddPartBinaryFromFile('c:\search.log',p);
    m.header.from:='youraddress@somewhere.com';
    m.header.tolist.add('You@somewhere.com');
    m.header.subject:='test message';
    m.EncodeMessage;
    //memo1.lines.assign(m.lines);

    if you wish to send it by SMTP too, then:
    SendToRaw('youraddress@somewhere.com',
              'You@somewhere.com',
              'your.smtp.server.com',
              m.lines,
              'yourusername',
              'yourpassword',
              'TargetPort');
    }
    p := m.AddPartMultipart('mixed', nil);
    l.loadfromfile(AttachFile);
    m.AddPartText(l,p);
    m.AddPartBinaryFromFile(AttachFile,p);
    m.header.from:=MailFrom;
    m.header.tolist.add(MailTo);
    m.header.subject:=Subject;
    m.EncodeMessage;

     Result := SendToRaw(MailFrom, MailTo, SMTPHost, m.Lines, Username, Password, TargetPort);
  finally
    m.free;
    l.free;
  end;
end; 


usage:
var t: TStrings;
  t.Add(your mess body text);

 SendAttach(SenderEmail, ReciptEmail, 'Subject', SmtpServerName,
                                    t,
                                     SmtpServerUser, SmtpServerPassword, inttostr(SmtpServerPort), AttachmentFileName); 

--- End code ---


Tested, ok.  :)

arneolav:
Download Synapse: http://synapse.ararat.cz/doku.php/download

Download  unit smtpclientlib: https://code.google.com/p/easy-synapse-smtpclient/source/browse/smtpclientlib_v2.pas


Sample usage:

--- Code: ---uses ... smtpclientlib;
    procedure TForm1.ButtonClick(Sender: TObject);
    var
      oSmtpClient: TSmtpClient;
    begin
      oSmtpClient := TSmtpClient.Create;
      try
        oSmtpClient.ServerAdress := 'smtp.mandrillapp.com';         ->>>error:  oSmtpClient.ServerDomain := 'smtp.mandrillapp.com';
        oSmtpClient.ServerPort := '587';
        oSmtpClient.ServerLoginUsername := 'me@here.com';
        oSmtpClient.ServerLoginPassword := 'difficult-and-long-password';
        oSmtpClient.MessageClear;
        oSmtpClient.BodyAsPlainText.Text := 'Plain body text.';
        oSmtpClient.BodyAsHtml.Text := '<html><head></head><body><h2>Html body text.</h2>
                                        <img src="C:\lazarus\examples\jpeg\lazarus.jpg" /></body></html>';
        oSmtpClient.AddInlineAttachment( 'C:\lazarus\examples\jpeg\lazarus.jpg' );
        oSmtpClient.AddAttachment( ExtractFilePath( ParamStr( 0 ) ) + 'project1.lpi' );
        if oSmtpClient.Send( 'info@company.com',          //mailfrom
                             'you@there.com',             //mailto
                             '',                          // copy to
                             '',                          // copy to
                             'Subject ... Buy more of our stuff' )    //Subject
                             then
          ShowMessage( 'Send ok' )
        else
          ShowMessage( oSmtpClient.SendResult );
      finally
        oSmtpClient.Free;
      end;
    end;

--- End code ---

You may copy Snyapse.pas -files into your directory (simpel way),
Better: Setup a path to your Synapse directory

vicot:
It would be nice if one of you guys (perhaps the maintainer of Synapse himself) released an updated version of Synapse featuring integrated support for attachments too.
Many newbies would not dare messing up with code to add a feature that is not officially supported.
Work on an all-inclusive new release would be very much appreciated.
Thanks.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version