(IF you have not done so,download the synapse lib. It does not need any installation, you will be in business instantly!)
Using pieces form demos by synapse and Trichview, I came up
with this example that shows how to send trichview content by email.
Make a unit with aTrichViewEdit component on it with embedded images.
add to the uses clause these synapse units:
MimePart,mimemess, smtpsend,blcksock, ssl_openssl,synautil;
put thes 2 files in the EXE directory:
libeay32.dll
libssl32.dll
Add "Send Email" Button and the .Button1Click procedure as shown below.
The procedure uses 2 other procedures shown herewith.
procedure TForm1.Fillthemessage(var MM : TMimeMess;subjecttext:string;cclist:Tstringlist);
var
MultiPartMix, MultiPartRel, MultiPartAlt: TMimePart;
newtext,newhtml: Tstringlist;
Stream: TmemoryStream;
i: integer;
SMTP : TSMTPSend;
begin
mm.header.subject:=subjecttext;
Stream := TMemoryStream.Create;
RichViewEdit1.SaveTextToStreamW('', Stream, 80, False, False);
Stream.Position := 0;
newtext:=tstringlist.Create;
newtext.LoadFromStream(Stream);
Stream.free;
Stream := TMemoryStream.Create;
RichViewEdit1.SaveHTMLToStreamEx(Stream, '', '', '', '', '', '',
[rvsoUseCheckpointsNames,{rvsoUTF8,}rvsoInlineCSS]);
Stream.Position := 0;
newhtml:=tstringlist.Create;
newhtml.LoadFromStream(Stream);
Stream.free;
//multiparts (parent-parts)
MultiPartMix := MM.AddPartMultipart('mixed', nil);
MultiPartRel := MM.AddPartMultipart('related', MultiPartMix);
MultiPartAlt := MM.AddPartMultipart('alternative', MultiPartRel);
//plain text-part
MM.AddPartText(newtext, MultiPartAlt);
newtext.free;
//html-part
MM.AddPartHTML(newHTML, MultiPartAlt);
newHTML.free;
//embedded images
for i := 0 to HTMLImages.Count-1 do begin
MM.AddPartHTMLBinary(HTMLImages.Stream,'','<'+HTMLImages.Name+'>',MultiPartRel);
end;
//attachments
for i:=0 to Attachments.count-1 do
MM.AddPartHTMLBinaryFromFile(Attachments,'',MultiPartMix);
//encode message
MM.EncodeMessage;
end;
function Sendmail(const MailFrom, MailTo, SMTPHost: string;
const MailData: TStrings; const Username, Password: string): Boolean;
var
SMTP: TSMTPSend;
s, t: string;
procedure showit(s:string);
begin
if result then
result:=false;
showmessage(s);
end;
begin
Result := true;
SMTP := TSMTPSend.Create;
try
// if you need SOCKS5 support, uncomment next lines:
// SMTP.Sock.SocksIP := '127.0.0.1';
// SMTP.Sock.SocksPort := '1080';
// if you need support for upgrade session to TSL/SSL, uncomment next lines:
SMTP.AutoTLS := True;
// if you need support for TSL/SSL tunnel, uncomment next lines: port 465:
// SMTP.FullSSL := True;
SMTP.TargetHost := Trim(SeparateLeft(SMTPHost, ':'));
s := Trim(SeparateRight(SMTPHost, ':'));
if (s <> '') and (s <> SMTPHost) then
SMTP.TargetPort := s;
SMTP.Username := Username;
SMTP.Password := Password;
If Not smtp.Login() Then
showit('SMTP ERROR: Login:' + smtp.EnhCodeString);
//If you successfully pass authorization to the remote server
If smtp.AuthDone Then Begin
//Send MAIL FROM SMTP command to set sender’s e-mail address.
If Not SMTP.MailFrom(GetEmailAddr(MailFrom), Length(MailData.Text)) then
showit('SMTP ERROR: MailFrom:' + smtp.EnhCodeString);
//Send RCPT TO SMTP command to set receiver’s e-mail address.
s := MailTo;
t := GetEmailAddr(Trim(FetchEx(s, ',', '"')));
if t <> '' then
If Not SMTP.MailTo(t) Then
showit('SMTP ERROR: MailTo:' + smtp.EnhCodeString);
//Send DATA SMTP command and transmit message data.
if not SMTP.MailData(MailData) Then
showit('SMTP ERROR: MailData:' + smtp.EnhCodeString);
End ELSE
showit('SMTP authorizacion ERROR:' + smtp.EnhCodeString);
//Close SMTP session (QUIT command) and disconnect from SMTP server.
If Not smtp.Logout() Then
showit('SMTP ERROR: Logout:' + smtp.EnhCodeString);
Finally
SMTP.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MM : TMimeMess;
{
MailFrom = E-mail address of the Sender
mailto = email address of the recipient
hostport : the smtp name of the web mail provider.optionally you can
concatenate the port number preceded by ':';
eg.smtp.live.com:587;
MailData= MIME embedded mail data created with Fillthemessage
Username: usernameas registered with the E-mail provider account
Password: password registered with the E-mail provider account;
}
begin
MM := TMimeMess.Create;
try
Fillthemessage(mm,'Test',CarboncopyList);
try
if not SendMail(MailFrom, MailTo, SMTPHost,MM.lines,Username, Password) then
showmessage('Failed')
except
on e: SysUtils.Exception do begin
ShowMessage(E.message);
end;
end;
finally
MM.Free;
end;
end;