Случай можно сказать канонический. Нужно отправлять почту через защищенное соединение. Увы, почтовики уже давно не работают по 25 порту.
Взял пример на Synapse. Под Windows все работает отлично. Но мне нужно это на Raspberry. Там разновидность Debian и lazarus работает без проблем.
Но вот именно отправка а=почты не работает из примера. Типа ошибка авторизации.
Попробуйте, пожалуйста приложенный код, у кого есть lazarus под Линуксами на IBM PC. Может, это вообще по UNIX работает не так, как в Windows...
- Код: Выделить всё
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
smtpsend,ssl_openssl,mimemess,mimepart;
type
{ TForm1 }
TForm1 = class(TForm)
Button2: TButton;
procedure Button2Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
Procedure MailSend(Const sSmtpHost, sSmtpPort, sSmtpUser, sSmtpPasswd, sFrom, sTo, sSubject, sMesBody: String);
Var
smtp: TSMTPSend;
msg_lines: TStringList;
Begin
msg_lines := TStringList.Create;
//Create SMTP object
smtp := TSMTPSend.Create;
Try
//Fill in the content of future mail
msg_lines.Add('From: ' + sFrom);
msg_lines.Add('To: ' + sTo);
msg_lines.Add('Subject: ' + sSubject);
If Length(sMesBody) > 0 Then
Begin
msg_lines.Add('');
msg_lines.Add(sMesBody);
End;
//====================================
//If authorization is required, then fill in username
smtp.UserName := sSmtpUser;
//Specify user's password
smtp.Password := sSmtpPasswd;
//Specify target server IP (or symbolic name)
smtp.TargetHost := sSmtpHost;
//Specify target server port
smtp.TargetPort := sSmtpPort;
//Enable SSL|TLS protocols
smtp.autoTLS := true;
smtp.FullSSL := True;
//Connect to SMTP server
If Not smtp.Login() Then
Showmessage('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(sFrom, Length(sFrom))Then
Showmessage('SMTP ERROR: MailFrom:' + smtp.EnhCodeString);
//Send RCPT TO SMTP command to set receiver’s e-mail address.
If Not smtp.MailTo(sTo) Then
Showmessage('SMTP ERROR: MailTo:' + smtp.EnhCodeString);
//Send DATA SMTP command and transmit message data.
If Not smtp.MailData(msg_lines) Then
Showmessage('SMTP ERROR: MailData:' + smtp.EnhCodeString);
End;
//Close SMTP session (QUIT command) and disconnect from SMTP server.
If Not smtp.Logout() Then
Showmessage('SMTP ERROR: Logout:' + smtp.EnhCodeString);
Finally
msg_lines.Free;
smtp.Free;
End;
End;
procedure TForm1.Button2Click(Sender: TObject);
begin
MailSend('smtp.mail.ru', '465', 'user', 'passw', 'from', 'to', 'subject', 'Message - To use this package in your code, first you have to add mfk_Synapse to the ‘Uses’ section of your module.');
end;
end.