cancel
Showing results for 
Search instead for 
Did you mean: 

Open Outlook email editor from SAP

0 Kudos

Hi,

I need to open the outlook email editor from ABAP program so that the user can manually input the To, CC, subject, body and attachment.

Can anybody help ?

Thanks and regards

Arijit Ghose

View Entire Topic
former_member182670
Contributor
0 Kudos

REPORT  ZTESTTTTT                               .

INCLUDE ole2incl .
DATA: lr_outlook TYPE OLE2_OBJECT,
      lr_mi TYPE OLE2_OBJECT.

CREATE OBJECT lr_outlook 'Outlook.Application'.

CALL METHOD OF lr_outlook 'CreateItem' = lr_mi
  EXPORTING #1 = 0.

CALL METHOD OF lr_mi 'Display'.

FREE OBJECT lr_outlook.
0 Kudos

Hi,

Thanks a lot. But, how do I enter values in To CC, Subjectand Body ?

Arijit

former_member182670
Contributor
0 Kudos

REPORT ztesttttt .

INCLUDE ole2incl .

DATA: lr_outlook TYPE ole2_object,

lr_mi TYPE ole2_object.

CREATE OBJECT lr_outlook 'Outlook.Application'.

CALL METHOD OF lr_outlook 'CreateItem' = lr_mi

EXPORTING #1 = 0.

SET PROPERTY OF lr_mi 'To' = 'your@to.address'.

SET PROPERTY OF lr_mi 'CC' = 'your@cc.address'.

SET PROPERTY OF lr_mi 'Subject' = 'Your subject'.

SET PROPERTY OF lr_mi 'Body' = 'Some text'.

CALL METHOD OF lr_mi 'Display'.

FREE OBJECT lr_outlook.

0 Kudos

Hi Tomasz,

It is super !! I need one more help.

Can I make the body multiline ?

Arijit

0 Kudos

Hi Tomasz,

Its great. How can I add a more than one line to body ?

also, the default signature set in outlook is not coming in this case. Please help. I have sent another email earlier.

Arijit

former_member182670
Contributor
0 Kudos

Here is an example with multiline body and default signature.


DATA: lr_outlook TYPE ole2_object,
      lr_mi TYPE ole2_object,
      lv_body TYPE string,
      lv_sig type string.

CREATE OBJECT lr_outlook 'Outlook.Application'.

CALL METHOD OF lr_outlook 'CreateItem' = lr_mi
  EXPORTING #1 = 0.

SET PROPERTY OF lr_mi 'To' = 'your@to.address'.
SET PROPERTY OF lr_mi 'CC' = 'your@cc.address'.
SET PROPERTY OF lr_mi 'Subject' = 'Your subject'.

CALL METHOD OF lr_mi 'Display'.


GET PROPERTY OF lr_mi 'Body' = lv_sig.



CONCATENATE 'First line' cl_abap_char_utilities=>newline
  INTO lv_body.
CONCATENATE lv_body 'Second line' cl_abap_char_utilities=>newline
  INTO lv_body.
CONCATENATE lv_body 'Third line' cl_abap_char_utilities=>newline
  INTO lv_body.

CONCATENATE lv_body lv_sig  INTO lv_body.

SET PROPERTY OF lr_mi 'Body' = lv_body.

FREE OBJECT lr_outlook.

Note that Outlook shows confirmation dialog box when a solution tries to programmatically access the following properties of the MaiItem object:

SentOnBehalfOfName

SenderName

ReceivedByName

ReceivedOnBehalfOfName

ReplyRecipientNames

To

CC

BCC

Body

HTMLBody

Recipients

SenderEmailAddress

So when you read the Body property to get default signature Outlook will ask for confirmation.

Please reward the posts that are helpful.

0 Kudos

Hi Tomasz,

Thanks a million !!

MY email id is arijit.ghose@cognizant.com

What is yours ?

Thanks and regards

Arijit Ghose

athavanraja
Active Contributor
0 Kudos

Hi Arijit,

Sorry for the delay. here is the topinclude code for the function i have mentioned. But Tomasz Mackowski has shown a better method and i guess its better to use that rather than this vb script method.

data: begin of int_receivers occurs 5.         " Receipients
               include structure soos1.
data: end   of int_receivers.

tables: sood,           " SAPoffice: Object definition
        soid,
        soud,
        tsp01.
data: begin of object_id.                " Identifies the object type
               include structure soodk.
data: end   of object_id.
data: begin of object_hd_change.
               include structure sood1.
data: end   of object_hd_change.

data: begin of folder_id.
               include structure soodk.
data: end   of folder_id.

data: begin of name_out.                   " SAP usernames & mail users
               include structure soud3.
data: end   of name_out.

data: rcode     like sy-subrc.

data: begin of objhead occurs 0.
               include structure soli.
data: end   of objhead.

data: begin of objpara occurs 0.
               include structure selc.
data: end   of objpara.

data: begin of objparb occurs 0.
               include structure soop1.
data: end   of objparb.

data: begin of receivers occurs 5.         " Receipients
               include structure soos1.
data: end   of receivers.
data: r_lines type p.               " Number of receipients

*data for Z_V_ARABIC_TRANS
data: wf_cntr1 like sy-tabix value 0,
      wf_cntr2 like sy-tabix value 0,
      wf_fld1(128),
      wf_fld2(128),
      wf_flen like sy-tabix,
      wf_index like sy-tabix value 0,
      wf_onechar(1),
      wf_onehex type x,
      wg_arabic(1),
      wf_offset like sy-tabix,   " Benin pointer
      wf_length like sy-tabix,   " End pointer
      wf_hex_inchar(2),
      wg_subrc like sy-subrc.

data: begin of int_word occurs 0,
        word(128),
      end of int_word.
data: begin of int_field occurs 0,
        offset like sy-tabix,
        length like sy-tabix,
      end of int_field.

Regards

Raja

Former Member
0 Kudos

hi athavan. can i have ur email id please?

tks.

samant

athavanraja
Active Contributor
former_member182670
Contributor
0 Kudos

You can find my email in <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=ggzzeye%2by6dpfoejrjqnvg%3d%3d">bc</a>

0 Kudos

Dear Tomasz,

Thanks for your code. It is working--can you please also provide code for adding attachments from the local system? Like we would like to attach a file from c:\temp directory?

Thank you,

Vijay

former_member198834
Participant
0 Kudos

This message was moderated.

ŁukaszPęgiel
Contributor