![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
создание TIdAttachment
Quattro © (2007-04-19 22:47:00)Добрый вечерочек.....подскажите, пожалуйста, как прикрепить файл к письму?
почему вот так не работает?
TForm3 = class(TForm)
MailMessage: TIdMessage;
AttachmentDialog: TOpenDialog;
ledHost: TLabeledEdit;
ledFrom: TLabeledEdit;
ledTo: TLabeledEdit;
ledCC: TLabeledEdit;
ledSubject: TLabeledEdit;
ledAttachment: TLabeledEdit;
Memo2: TMemo;
Label1: TLabel;
btnSendMail: TBitBtn;
Memo1: TMemo;
Button1: TButton;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
SMTP: TIdSMTP;
procedure btnSendMailClick(Sender: TObject);
procedure SMTPStatus(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: string);
procedure Button1Click(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.btnSendMailClick(Sender: TObject);
begin
Memo1.Clear;
// установка SMTP
SMTP.Host:=ledHost.Text;
SMTP.Port:=25;
// установка сообщения
Smtp.AuthType:=atNone; // atNone
Smtp.Username:=LabeledEdit1.Text;
Smtp.Password:=LabeledEdit2.Text;
//
MailMessage.From.Name:=ledFrom.Text;
MailMessage.Subject:=ledSubject.Text; // тема
MailMessage.From.Address:=ledFrom.Text; // адрес отправителя
MailMessage.Recipients.EMailAddresses:=ledTo.Text+','+ledCC.Text; // получатель + копия
MailMessage.Body.Text:=Memo2.Text; // текст сообщения
if FileExists(ledAttachment.Text)
then TIdAttachment.Create(MailMessage.MessageParts,ledAttachment.Text);
// отправка почты
try
try
SMTP.Connect(1000);
SMTP.Send(MailMessage);
ShowMessage('Письмо отправлено!');
except on E:Exception do
begin
Memo1.Lines.Insert(0,'Статус отправки: ERROR - '+E.Message);
ShowMessage('Письмо не отправлено!');
end;
end;
finally
if SMTP.Connected
then SMTP.Disconnect;
end;
end;
procedure TForm3.SMTPStatus(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: string);
begin
Memo1.Lines.Insert(0,'Статус отправки: '+AStatusText);
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
if AttachmentDialog.Execute
then ledAttachment.Text:=AttachmentDialog.FileName;
end;
end.
Megabyte (2007-04-20 09:49:00) [1]Даже не зная английского, по-моему тут все понятно: нет перегруженных версий данного метода, вызываемых с подобными параметрами. Убери нафиг параметры, в данном методе они не нужны.
Quattro (2007-04-19 22:49:00) [2]ещё вопросик...почему
SMTP.Connect(1000);
ругается There is no overloaded version of 'Connect' that can be called with these arguments