Skip to Content
0
Jan 29, 2008 at 08:19 AM

Send smartform as pdf attachment to external eamil

61 Views

Hi Experts,

I want to send my smartform output as pdf attachment to esternal eamil address 'SMTP address'

e.g. emailid@company.com

I ahve used below code but email goes to SAP inbox in mail body not as attachment i want attachment in the email id such as above example

Code i have used -


Local data:

DATA:

ls_control_param TYPE ssfctrlop, "Control paramters

ls_output_options TYPE ssfcompop. "Output options

  • Data for email smart form:

DATA:

lv_ip_mailaddr TYPE so_name, "Address of a Mail Recipient

lv_ip_type_id TYPE so_escape, "Recipient type

ls_recipient_id TYPE swotobjid, "Structure for recvr obj ID

ls_sender_id TYPE swotobjid. "Structure for sender obj id

  • Constants:

CONSTANTS:

lc_ip_type_id TYPE so_escape VALUE 'U', "For internet address.

lc_smartform TYPE tdsfname VALUE 'ZVSF_ASN_DELNOTE', "Smart form name

lc_mail TYPE tddevice VALUE 'MAIL'. "Mail device

  • Assign recipient

lv_ip_mailaddr = gv_smtp_addr. "CSAM email id

lv_ip_type_id = lc_ip_type_id. "External address

  • Create Mail title

CONCATENATE text-001

nast-objky

INTO ls_output_options-tdtitle.

  • Create recipient object

CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'

EXPORTING

ip_mailaddr = lv_ip_mailaddr

ip_type_id = lv_ip_type_id

IMPORTING

ep_recipient_id = ls_recipient_id

EXCEPTIONS

invalid_recipient = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • error handling

cf_retcode = sy-subrc.

PERFORM protocol_update.

ENDIF.

  • Get sender object id.

CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'

EXPORTING

ip_sender = sy-uname

IMPORTING

ep_sender_id = ls_sender_id

EXCEPTIONS

invalid_sender = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • error handling

cf_retcode = sy-subrc.

PERFORM protocol_update.

ENDIF.

  • Assign the smart form name

w_ssfname = lc_smartform.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = w_ssfname

IMPORTING

fm_name = lf_fm_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • error handling

cf_retcode = sy-subrc.

PERFORM protocol_update.

ENDIF.

  • Control parameters.

  • For Print output:

IF nast-nacha = '1'. "Print output

ls_control_param-preview = 'X'.

ls_control_param-no_dialog = 'X'.

ENDIF.

  • For fax/email output.

IF nast-nacha = '2'. "Fax/Email

  • Output options

ls_output_options-tdteleland = gs_kna1-land1.

ls_output_options-tdtelenum = gs_kna1-telfx.

ls_output_options-tdfaxuser = sy-uname.

ls_output_options-BCS_COMMIT = 'X'.

ls_control_param-device = lc_mail.

ENDIF.

  • dynamically call Fm behind the Smart form

CALL FUNCTION lf_fm_name

EXPORTING

control_parameters = ls_control_param

mail_recipient = ls_recipient_id

mail_sender = ls_sender_id

output_options = ls_output_options

user_settings = ' '

TABLES

delivery = gt_delivery

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

IF sy-subrc <> 0.

  • Error handling

cf_retcode = sy-subrc.

PERFORM protocol_update.

ENDIF.

IF NAST-NACHA = '2'.

ls_control_param-device = 'TELEFAX'.

CALL FUNCTION lf_fm_name

EXPORTING

control_parameters = ls_control_param

  • mail_recipient = ls_recipient_id

  • mail_sender = ls_sender_id

output_options = ls_output_options

user_settings = ' '

TABLES

delivery = gt_delivery

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

IF sy-subrc <> 0.

  • Error handling

cf_retcode = sy-subrc.

PERFORM protocol_update.

ENDIF.

ENDIF.

Can any one help me regarding this issue.

Points will be rewarded

Thanks in advance,

Dhanu