Hello everyone!
I am using IDE Laz4android 2.0.0 with LAMW.
It is necessary to send a simple text Email from my Android application.
To do this, I installed the Synapse libraries, using the
SMTPSend,
ssl_openssl modules (for encryption on port 465).
But this does not work for me under Android, everything compiles and starts without errors, but the emails do not go away.
In the "libs \ armeabi-v7a" project folder, I put two ssl libraries
“libcrypto.so" and
"libssl.so” version 1.0.2j, tried other versions of these libraries, to no avail.
In the
SendToRaw function of the
SMTPsend.pas module, I checked that
FullSSL is enabled:
function SendToRaw(const MailFrom, MailTo, SMTPHost: string;
const MailData: TStrings; const Username, Password: string): Boolean;
var
SMTP: TSMTPSend;
s, t: string;
begin
Result := False;
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:
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 SMTP.Login then
begin
if SMTP.MailFrom(GetEmailAddr(MailFrom), Length(MailData.Text)) then
begin
s := MailTo;
repeat
t := GetEmailAddr(Trim(FetchEx(s, ',', '"')));
if t <> '' then
Result := SMTP.MailTo(t);
if not Result then
Break;
until s = '';
if Result then
Result := SMTP.MailData(MailData);
end;
SMTP.Logout;
end;
finally
SMTP.Free;
end;
end;
The following is an excerpt from my code:
Procedure SendMail (Host, Subject, pTo, From , TextBody, HTMLBody, login,password : string);
var Msg : TMimeMess; // message
StringList : TStringList; // message content
MIMEPart : TMimePart; // parts of the message
begin
Msg := TMimeMess.Create; // create new message
StringList := TStringList.Create;
try
// add headers
Msg.Header.Subject := Subject; // Message subject
Msg.Header.From := From; // name and address of sender
Msg.Header.ToList.Add(pTo); // recipient name and address
// create the root element
MIMEPart := Msg.AddPartMultipart('alternative', nil);
if length(TextBody)=0 then
// if format HTML
begin
StringList.Text := HTMLBody;
Msg.AddPartHTML(StringList, MIMEPart);
end
else
// if text format
begin
StringList.Text := TextBody;
Msg.AddPartText(StringList, MIMEPart);
end;
// encode and send
Msg.EncodeMessage;
// send
if smtpsend.SendToRaw(From,pTo,Host,Msg.Lines,login,password) then
ConnectForm.ShowMessage('Email Sent')
else
ConnectForm.ShowMessage('Email NOT Sent');
finally
Msg.Free;
StringList.Free;
end;
end;
procedure TConnectForm.jButton1Click(Sender: TObject);
begin
SendMail('smtp.gmail.com:465',
'test email subject',
'recipient@gmail.com',
'sender@gmail.com’,
'The content of the letter in text format',
'',
'sender@gmail.com’, 'password')
end;
Under Windows I checked, everything works fine (using the openssl, libeay32.dll and ssleay32.dll libraries). How to make it work under Android? Maybe someone faced such a problem?
In the folder with demos
lazandroidmodulewizard, there were no examples of sending e-mail, there is only the jcMail component that can only receive e-mails, and not send. If anyone knows the solution, or shows a working example, I will be very grateful.