Задача простая – залогиниться на серваке и отправить сообщение на мыло. В дельфях мало понимаю, поэтому не стебите особо плиз… вобщем, состряпала по мануалам в borland дельфях 7 следующий код:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdMessage, IdSMTP, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdMessageClient, IdPOP3, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
IdPOP31: TIdPOP3;
SMTP: TIdSMTP;
IdMessage: TIdMessage;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SMTP.Port:=25;
SMTP.Host:='smtp.mail.ru';
SMTP.Username:='vasya@mail.ru';
SMTP.Password:='12345666';
SMTP.AuthenticationType:=atLogin;
with IdMessage do
begin
Body.Assign(Memo1.Lines);
From.Text := 'vasya@mail.ru';
Recipients.EMailAddresses := 'masha@mail.ru';
Subject := 'hello';
end;
SMTP.Connect;
try
showmessage('Произошло подключение к серверу');
SMTP.Send(IdMessage);
finally
SMTP.Disconnect;
end;
end;
end.
Admin:
Учимся правильно оформлять код!
При нажатии на кнопку ‘послать’ все виснет и вылезает ошибка на строке SMTP.Host:='smtp.mail.ru';
Debugger Exception Notification:
Project Project.exe raised exception class EAccess Violation with message ‘Access violation at address 0046E5EE in module ‘Project.exe’. Read of address 00000000’. Process stopped…
Как с этим бороться? Что я делаю не так? И еще маленький вопрос: как к сообщению приаттачить файл ? например файл с:\1.txt