Board index » delphi » Sending mail with attachment

Sending mail with attachment

 I am developing an app which have to send an email with attachment. Here is an excerpt from the code:

  Mes := TIdMessage.Create(nil);
  with Mes do
  begin
    Recipients.EMailAddresses := ToMail;
    From.Text := FromMail;
    Subject := 'Published';
    Priority := mpNormal;
    Body.Text := 'haya';
  end;
  Attch := TIdAttachment.Create(Mes.MessageParts, FName);
  Mail.Send(Mes);

It just don't send. I wait for it for ages. Withouth the line for the attachment everything is OK, and the mail is sent.
Need some help fast, please!

 

Re:Sending mail with attachment


Try to connect to server before sending :
For ex. :

Mail.Host := 'YourServerName';
Mail.Username := 'YourUserName';
Mail.Connect;
if Mail.Connected then begin
    Mail.Send(Mes);
    Mail.Disconnect;
end;

"Probe" <nos...@yahoo.com> a crit dans le message de news:
3cf25cba$1_1@dnews...

Quote

>  I am developing an app which have to send an email with attachment. Here

is an excerpt from the code:
Quote

>   Mes := TIdMessage.Create(nil);
>   with Mes do
>   begin
>     Recipients.EMailAddresses := ToMail;
>     From.Text := FromMail;
>     Subject := 'Published';
>     Priority := mpNormal;
>     Body.Text := 'haya';
>   end;
>   Attch := TIdAttachment.Create(Mes.MessageParts, FName);
>   Mail.Send(Mes);

> It just don't send. I wait for it for ages. Withouth the line for the

attachment everything is OK, and the mail is sent.
Quote
> Need some help fast, please!

Re:Sending mail with attachment


I am already connected :)
I said it is an excerpt from the actual code.
It works without the attachment line. It doesent with it.

Quote
"Stophe" <gu...@free.fr> wrote:
>Try to connect to server before sending :
>For ex. :

>Mail.Host := 'YourServerName';
>Mail.Username := 'YourUserName';
>Mail.Connect;
>if Mail.Connected then begin
>    Mail.Send(Mes);
>    Mail.Disconnect;
>end;

>"Probe" <nos...@yahoo.com> a crit dans le message de news:
>3cf25cba$1_1@dnews...

>>  I am developing an app which have to send an email with attachment. Here
>is an excerpt from the code:

>>   Mes := TIdMessage.Create(nil);
>>   with Mes do
>>   begin
>>     Recipients.EMailAddresses := ToMail;
>>     From.Text := FromMail;
>>     Subject := 'Published';
>>     Priority := mpNormal;
>>     Body.Text := 'haya';
>>   end;
>>   Attch := TIdAttachment.Create(Mes.MessageParts, FName);
>>   Mail.Send(Mes);

>> It just don't send. I wait for it for ages. Withouth the line for the
>attachment everything is OK, and the mail is sent.
>> Need some help fast, please!

Other Threads