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
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 Email with Outlook

Discussion in 'Delphi Programming' started by AdminDF, Nov 30, 2013.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    creating an instance of outlook or attaching to an open instance of outlook. Takes a little more code but it works (outlook 2003, 2007, 2010,???)[/size]NOTE: This is not complete code but it should get you pointed in the right direction. I use it in a program that does some stuff and then emails the results back to the user. So you will not have to use all the getusername stuff and change the recipient add to who the email needs to go to.


    Code:
    procedure TForm1.SendEmail;
    const
      olMailItem = 0;
      olByValue = 1;
      olByReference = 4;
      olEmbeddedItem = 5;
      olOLE = 6;
      olFormatHTML = 2;
      olFormatPlain = 1;
      olFormatRichText = 3 ;
      olFormatUnspecified = 0;
    var
      outlook_opened  : boolean;
      oNameSpace,
      Outlook: OleVariant;
      vMailItem: variant;
    begin
        outlook_opened := False;
       _Size := 256;
        GetUserName(@_user,_size);
        try
          Outlook := GetActiveOleObject('Outlook.Application');
        except
          Outlook := CreateOleObject('Outlook.Application');
          oNameSpace := Outlook.GetNamespace('MAPI');
          oNameSpace.Logon('', '', False, True);
          outlook_opened := True;
        end;
        vMailItem := Outlook.CreateItem(olMailItem);
        vMailItem.Recipients.Add(_user + '@outlook.com');
        vMailItem.Subject := 'Sending EMail in Outlook';
        vMailItem.Body := 'Body text goes here.';
        vMailItem.BodyFormat:= olFormatHTML;
        if FileExists(_fname) then
        begin
          vMailItem.Attachments.Add(_fname);
        end;
        try
          vMailItem.Send;
        Except
          On E:Exception Do
            MessageDlg(E.Message,mtWarning,[mbOK],0);
        End;
        if outlook_opened then
        begin
          oNameSpace.Logoff;
          VarClear(Outlook);
        end;
    end;
     

Share This Page