1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Sending mail without an eMail Client

Discussion in 'Delphi Programming' started by Beast Power, Nov 2, 2015.

  1. Beast Power
    Online

    Beast Power DF Expert

    This does not use an eMail Client to send mail, but sends mail directly

    You will need to use indy projects components, get it here http://www.indyproject.org/index.en.aspx

    This is the code that I use and works well for me.


    Code:
          idsmtp: TIdSMTP;
          idmsgMailMessage: TIdMessage;
    
    Code:
    function SendMail(cMessage, cAttachment: string; cBody: TStrings; cTo, cFrom, cSMTP, cSMTPUser, cSMTPPassword: string): Boolean;
    var cMailToStr, cMailTmp, cMail: string;
       nMails, xyz: Integer;
       lRemAtt: Boolean;
    begin
       SendMail := True;
    // For Display  'Busy .. Sending'
    
       if cSMTP.Text <> '' then begin
          try
             if not idmsgMailMessage.IsBodyEmpty then
                idmsgMailMessage.ClearBody;
             if idmsgMailMessage.MessageParts.AttachmentCount > 0 then
                idmsgMailMessage.MessageParts.Clear; 
          except
    
          end;
    
      //setup SMTP
          idSMTP.Host := cSMTP;
          idSMTP.Port := 25;
          idSMTP.Username := cSMTPUser;
          idSMTP.Password := cSMTPPassword;
    
          idmsgMailMessage.From.Address := cFrom;
          idmsgMailMessage.Recipients.EMailAddresses := cTo;
    
          idmsgMailMessage.Subject := cMessage;
          idmsgMailMessage.Body.AddStrings(cBody);
          lRemAtt := False;
          if cAttachment <> '' then
             if FileExists(cAttachment) then begin
                TIdAttachmentFile.Create(idmsgMailMessage.MessageParts, cAttachment);
                lRemAtt := True;
             end;
    
      //send mail
          try
             try
                idSMTP.Connect;
                idSMTP.Send(idmsgMailMessage);
             except on E: Exception do
                begin
          //  For Display   'ERROR: ' + E.Message;
                   SendMail := False;
                end;
             end;
          finally
             if idSMTP.Connected then idSMTP.Disconnect;
             // For Display  'Email .. Sent'
             try
                if lRemAtt then
                   idmsgMailMessage.MessageParts.Clear;
                if not idmsgMailMessage.IsBodyEmpty then
                   idmsgMailMessage.ClearBody;
                if idmsgMailMessage.MessageParts.AttachmentCount > 0 then
                   idmsgMailMessage.MessageParts.Clear;
             except
    
             end;
    
          end;
       end;
    end;
    
     

     
     
    jlead and rendou like this.
  2. projectantix
    Offline

    projectantix Guest

    great post, what email service would you recommend using with this? gmail? hotmail? aol? what works best for you?
     
  3. evaguiar
    Online

    evaguiar DF Junior

    I was looking for this information, thanks a lot!
     
  4. profepaco
    Offline

    profepaco DF Junior

    I have problems to use this...

    sending an email using google accounts is really more complicated.
     
  5. digitallan
    Offline

    digitallan Guest

    thank you my friend
     

Share This Page