rel. 9
uses IdMessage
TIdAttachment.Create(MailMessage.MessageParts, ledAttachment.Text);
rel.10
uses IdAttachmentFile
TIdAttachmentFile.Create(IdMessage.MessageParts, EdAllegato.Text);
[b]IdAttachmentFile[/b] specifico della versione 10 di Indy, hanno modificato
le classi di gestione allegati presenti fino alla rel. 9 nella unit IdMessage
//si possono visualizzare le operazioni durante la connessione
//al server di posta
//
procedure Tfrm_InvioMail.IdSMTPStatus(ASender: TObject;
const AStatus: TIdStatus; const AStatusText: string);
begin
MemoStato.Lines.Insert(0,'Status: ' + AStatusText);
end;
procedure Tfrm_InvioMail.act_InvioMailExecute(Sender: TObject);
begin
MemoStato.Clear;
IdSMTP.Host := EdHost.Text; //indirizzo posta uscita del server
IdSMTP.Port := 25; //porta utilizzata dal servizio email
//configurazione messaggio mail
IdMessage.From.Address := EdMittente.Text;
IdMessage.Recipients.EMailAddresses := EdDestinatario.Text + ',' + EdConoscenza.Text;
IdMessage.Subject := EdOggetto.Text;
IdMessage.Body.Text := EdCorpo.Text;
//per selezioneare l'allegato si puo' utilizzare il compponente standard OpenDialog
//
if FileExists(EdAllegato.Text) then
TIdAttachmentFile.Create(IdMessage.MessageParts, EdAllegato.Text);
//invio mail
try
try
IdSMTP.Connect; //connessione
IdSMTP.Send(IdMessage);
except on E:Exception do
//
//segnalazione eventuale problema di connessione
MemoStato.Lines.Insert(0, 'ERROR: ' + E.Message);
end;
finally
//segnalazione invio effettuato
MemoStato.Lines.Insert(0, 'ERROR: ' + E.Message);
if IdSMTP.Connected then IdSMTP.Disconnect; //disconnessione dal server di posta
end;
end;