REPORT yknctest01 NO STANDARD PAGE HEADING. INCLUDE ole2incl. * handles for OLE objects DATA: h_olook TYPE ole2_object, h_email TYPE ole2_object, h_attch TYPE ole2_object. DATA: h_wshel TYPE ole2_object. *Sub SendMailWithOutlook() * * 'variables * Set OApp = CreateObject("Outlook.Application") * Set OMail = OApp.CreateItem(olMailItem) * * With OMail * * .Subject = "Pay Slip for " & PayMonth & " Attached as XLS File" * * .To = EmailId * * .Body = "Dear " & Name & "," & vbCrLf & vbCrLf & _ * "Please find enclosed the salary slip" & vbCrLf & _ * "for the month of " & PayMonth & "." & vbCrLf & vbCrLf & _ * "Regards," & vbCrLf & vbCrLf & _ * "HR Girl" & vbCrLf & vbCrLf & _ * "Assistant Manager - HR" & vbCrLf & _ * "Mobile: +91 98888 77777" & vbCrLf & _ * "Email: hrgirl@pcbl.com" & vbCrLf * * .Attachments.Add (DirName & "\" & NewWbk) * * .Importance = olImportanceHigh * * .BodyFormat = olFormatRichText * * .Save * * .Display * * Application.Wait (Now + TimeValue("00:00:02")) * * 'this bypasses the security mechanism so that a mail goes out immediately * Set WshShell = CreateObject("WScript.Shell") * WshShell.AppActivate OMail * WshShell.SendKeys ("%s") ' sends a CTRL-S as if the user himself typed it in the application * Application.Wait (Now + TimeValue("00:00:03")) * End With * * Set OMail = Nothing * * Set OApp = Nothing * * Exit Sub * *End Sub *&---------------------------------------------------------------------* *& Event START-OF-SELECTION *&---------------------------------------------------------------------* START-OF-SELECTION. * start Outlook CREATE OBJECT h_olook 'Outlook.Application'. PERFORM err_hdl. CALL METHOD OF h_olook 'CreateItem' = h_email EXPORTING #1 = 0. " olMailItem=0 PERFORM err_hdl. SET PROPERTY OF h_email 'Subject' = 'Test Subject'. SET PROPERTY OF h_email 'To' = 'vinoddwivedi81@gmail.com;ssscal@gmail.com;vinod.dwivedi@rediffmail.com;vinod_developer2004@yahoo.com'. SET PROPERTY OF h_email 'Body' = 'Hi! Hello this is test mail'. GET PROPERTY OF h_email 'Attachments' = h_attch. PERFORM err_hdl. CALL METHOD OF h_attch 'Add' = h_attch EXPORTING #1 = 'C:\gt_struct.xls'. SET PROPERTY OF h_email 'Importance' = 2. "olImportanceHigh CALL METHOD OF h_email 'Save'. CALL METHOD OF h_email 'Display'. WAIT UP TO 2 SECONDS. CREATE OBJECT h_wshel 'WScript.Shell'. PERFORM err_hdl. CALL METHOD OF h_wshel 'AppActivate' EXPORTING #1 = 'Test Subject'. " As SUBJECT is Title of Window PERFORM err_hdl. CALL METHOD OF h_wshel 'SendKeys' EXPORTING #1 = '%s'. PERFORM err_hdl. WAIT UP TO 2 SECONDS. FREE OBJECT h_attch. PERFORM err_hdl. FREE OBJECT h_email. PERFORM err_hdl. FREE OBJECT h_olook. PERFORM err_hdl. FREE OBJECT h_wshel. PERFORM err_hdl. *&---------------------------------------------------------------------* *& Form ERR_HDL *&---------------------------------------------------------------------* FORM err_hdl. IF sy-subrc <> 0. WRITE: / 'Fehler bei OLE-Automation:'(010), sy-subrc. STOP. ENDIF. ENDFORM. " ERR_HDL