Multiple Email Address For Single Vendor

The client wants to have two email addresses for one vendor. The requirement is to send off one PO to two different email addresses as per the business process requirement. 

Solution:

You can make a distribution group address containing both email address the maintain this distribution group address in vendor master record. 

Or

You can solved it using ABAP:

- Function module ME_PRINT_PO has been copied in order to change the Perform "PREPARE_FORMULAR" by "zPREPARE_FORMULAR" and Perform "ENDE" by "zENDE".

Coding:

- Include LZMEDRUCKF01 has been changed by adding a new form  "f_send_mail

*& 
*&      Form  f_send_mail 
*& 

form f_send_mail changing p_retco. 

* initialise 

  clear i_pdf[]. 
  clear i_pack[]. 
  clear i_head[]. 
  clear i_cont[].   "binary data in PDF format 
  clear i_cont1[]. 
  clear i_rec[]. 
  clear i_otf255[]. 
  clear wa_doc. 
  clear wa_addr. 
  clear w_size_in. 
  clear w_size_out. 

* 1) receiver list 

  call function 'ADDR_GET_COMPLETE' 

    EXPORTING 
      ADDRNUMBER                    = lfa1-adrnr 
    IMPORTING 
      ADDR1_COMPLETE                = wa_addr 
    EXCEPTIONS 
      PARAMETER_ERROR               = 1 
      ADDRESS_NOT_EXIST             = 2 
      INTERNAL_ERROR                = 3 
      WRONG_ACCESS_TO_ARCHIVE       = 4 
      OTHERS                        = 5. 

  if sy-subrc ne 0. 
*   no action 
  else.

    loop at wa_addr-adsmtp_tab into wa_smtp.

      translate wa_smtp-adsmtp-remark to upper case.

      if wa_smtp-adsmtp-flgdefault eq c_charx
        or wa_smtp-adsmtp-remark eq 'ORDER'.
        move wa_smtp-adsmtp-smtp_addr to wa_rec-receiver.
        move c_charu                  to wa_rec-rec_type.
        m_save wa_rec i_rec.
      endif.

      clear wa_smtp.

    endloop.

    if sy-subrc eq 0. 

*  2) mail attributes 

     move nast-objky to wa_doc-obj_name. 
     move nast-objky to wa_doc-obj_descr. 
     move sy-langu   to wa_doc-obj_langu. 
     move c_charp    to wa_doc-sensitivty. 
     move c_charx    to wa_doc-no_change. 

*  3) mail contents 

      append lines of i_otf to i_otf255. 

      call function 'SX_OBJECT_CONVERT_OTF_PDF' 

           exporting 
                format_src  = 'OTF' 
                format_dst  = 'PDF' 
                devtype     = 'ASCIIPRI' 
                len_in      = w_size_in 
           importing 
                len_out     = w_size_out 
           tables 
                content_in  = i_otf255 
                content_out = i_cont. 

      if sy-subrc ne 0. 

*       error creating attachment 

        move c_char1 to p_retco. 

        call function 'NAST_PROTOCOL_UPDATE' 

          exporting 
            msg_arbgb                    = 'ZSC' 
            msg_nr                       = '618' 
            msg_ty                       = c_chare 
          EXCEPTIONS 
            MESSAGE_TYPE_NOT_VALID       = 1 
            NO_SY_MESSAGE                = 2 
            OTHERS                       = 3. 

        if sy-subrc ne 0. 
*         no action 
        endif. 
      else. 

* 4) mail body 

      concatenate 'Attachment:'(001) nast-objky 
                    into wa_cont-line separated by space. 

        m_save wa_cont i_cont1. 

        move 'Kind regards'(002) to wa_cont-line. 

        m_save wa_cont i_cont1. 

* 5) title of the attachment 

       move nast-objky to wa_cont-line. 

       m_save wa_cont i_head. 

* 6) describe contents 

       clear wa_pack-transf_bin. 

       move c_char1    to wa_pack-head_start. 
       move c_char0    to wa_pack-head_num. 
       move c_char1    to wa_pack-body_start. 

       describe table i_cont1 lines wa_pack-body_num. 

       move 'RAW'      to wa_pack-doc_type. 

       m_save wa_pack i_pack. 

       move c_charx    to wa_pack-transf_bin. 
       move c_char1    to wa_pack-head_start. 
        move c_char1    to wa_pack-head_num. 
        move c_char1    to wa_pack-body_start. 

        describe table i_cont lines wa_pack-body_num. 

        move 'PDF'      to wa_pack-doc_type. 
        move nast-objky to wa_pack-obj_name. 
        move nast-objky to wa_pack-obj_descr. 
        move w_size_out to wa_pack-doc_size. 

        m_save wa_pack i_pack. 

* 7) sent mail + PDF attachment to internet address 

        call function 'SO_NEW_DOCUMENT_ATT_SEND_API1' 

             exporting 
                  document_data              = wa_doc 
                  put_in_outbox              = c_charx 
             tables 
                  packing_list               = i_pack 
                  object_header              = i_head 
                  contents_bin               = i_cont 
                  contents_txt               = i_cont1 
                  receivers                  = i_rec 
             exceptions 
                  too_many_receivers         = 1 
                  document_not_sent          = 2 
                  document_type_not_exist    = 3 
                  operation_no_authorization = 4 
                  parameter_error            = 5 
                  x_error                    = 6 
                  enqueue_error              = 7 
                  others                     = 8. 

        if sy-subrc ne 0. 
*         error sending mail 
          move c_char1 to p_retco. 
          move nast-objky to sy-msgv1. 

          call function 'NAST_PROTOCOL_UPDATE' 

            exporting 
              msg_arbgb                    = 'ZSC' 
              msg_nr                       = '619' 
              msg_ty                       = c_chare 
              MSG_V1                       = sy-msgv1 
            EXCEPTIONS 
              MESSAGE_TYPE_NOT_VALID       = 1 
              NO_SY_MESSAGE                = 2 
              OTHERS                       = 3. 

          if sy-subrc ne 0. 
*           no action 
          endif. 
        else. 

*         mail successfully send 

          move nast-objky to sy-msgv1. 

          call function 'NAST_PROTOCOL_UPDATE' 

            exporting 
              msg_arbgb                    = 'ZSC' 
              msg_nr                       = '620' 
              msg_ty                       = c_chars 
              MSG_V1                       = sy-msgv1 
            EXCEPTIONS 
              MESSAGE_TYPE_NOT_VALID       = 1 
              NO_SY_MESSAGE                = 2 
              OTHERS                       = 3. 

          if sy-subrc ne 0. 
*           no action 
          endif. 

        endif. 

      endif. 

    else. 

*     no recipients 

      move c_char1 to p_retco. 
      move nast-objky to sy-msgv1. 
      move lfa1-lifnr to sy-msgv2. 

      call function 'NAST_PROTOCOL_UPDATE' 

        exporting 
          msg_arbgb                    = 'ZSC' 
          msg_nr                       = '621' 
          msg_ty                       = c_chare 
          MSG_V1                       = sy-msgv1
          msg_v2                       = sy-msgv2 
        EXCEPTIONS 
          MESSAGE_TYPE_NOT_VALID       = 1 
          NO_SY_MESSAGE                = 2 
          OTHERS                       = 3. 

      if sy-subrc ne 0. 
*       no action 
      endif. 

    endif. 

  endif. 

endform.                    " f_send_mail

- Include LZMEDRUCKTOP

* workfields * 

data:   w_rec      type char30. 
data:   w_size_in  like sood-objlen. 
data:   w_size_out like sood-objlen. 

* structures * 

data:   wa_doc     type sodocchgi1. 
data:   wa_cont    type solisti1. 
data:   wa_pack    type sopcklsti1. 
data:   wa_addr    type SZADR_ADDR1_COMPLETE. 
data:   wa_smtp    type SZADR_ADSMTP_LINE. 
data:   wa_rec     type somlreci1. 

* internal tables * 

data:   i_otf      type standard table of itcoo. 
data:   i_pdf      type standard table of tline. 
data:   i_otf255   type standard table of solisti1. 
data:   i_cont     type standard table of solisti1. 
data:   i_cont1    type standard table of solisti1. 
data:   i_head     type standard table of solisti1. 
data:   i_pack     type standard table of sopcklsti1. 
data:   i_rec      type standard table of somlreci1. 

- Create a ZLMEDRUCKF1O

*&---------------------------------------------------------------------*
*&      Form  ZPREPARE_FORMULAR
*&---------------------------------------------------------------------*
*       copy from LMEDRUCKF1O form PREPARE_FORMULAR
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

form zprepare_formular using p_screen     type c           " note 353318
                           value(p_toa_dara) type toa_dara" 353318
                           p_arc_params type arc_params  " note 353318
                           p_fonam      like tnapr-fonam"214570#353318
                    changing p_retco      type i.          " note 353318

  clear p_retco.

  data: xdevice(10),                   "Hilfsfeld Formular
        xprogramm type  tdprogram,     "Hilfsfeld Programm
        xdialog.                       "Hilfsfeld Formular

  set language ekko-spras.
  set country  lfa1-land1.

*- Formular festlegen -------------------------------------------------*
*  select single * from  tnapr                  "HW 214570
*       where    kschl  = nast-kschl            "HW 214570
*       and    nacha  = nast-nacha              "HW 214570
*       and    kappl  = nast-kappl.             "HW 214570

  tnapr-fonam = p_fonam.                                    "HW 214570

  if tnapr-fonam eq space.
    tnapr-fonam = 'MEDRUCK'.
  endif.

  clear: xdialog, xdevice, itcpo.

  move-corresponding nast to itcpo.

  itcpo-tdtitle = nast-tdcovtitle.
  itcpo-tdfaxuser = nast-usnam.

*- Ausgabemedium festlegen --------------------------------------------*

  case nast-nacha.

    when '2'.

      xdevice = 'TELEFAX'.

      if nast-telfx eq space.
        xdialog = 'X'.
      else.

        itcpo-tdtelenum  = nast-telfx.

        if nast-tland is initial.
          itcpo-tdteleland = lfa1-land1.
        else.
          itcpo-tdteleland = nast-tland.
        endif.

      endif.

    when '3'.

      xdevice = 'TELETEX'.

      if nast-teltx eq space.
        xdialog = 'X'.
      else.
        itcpo-tdtelenum  = nast-teltx.
        itcpo-tdteleland = lfa1-land1.
      endif.

    when '4'.

      xdevice = 'TELEX'.

      if nast-telx1 eq space.
        xdialog = 'X'.
      else.
        itcpo-tdtelenum  = nast-telx1.
        itcpo-tdteleland = lfa1-land1.
      endif.

    when '5'.

      clear itcpo-tdimmed.
      clear xdialog.

      move c_charx to itcpo-tdgetotf. "Return OTF-data
      move 'PRINTER' to xdevice.

    when others.

      xdevice = 'PRINTER'.

      if nast-ldest eq space.
        xdialog = 'X'.
      else.
        itcpo-tddest   = nast-ldest.
      endif.

  endcase.

*- Testausgabe --------------------------------------------------------*

  if p_screen ne space.

*- Testausgabe auf Bildschirm -----------------------------------------*

*   IF NAST-TCODE EQ 'XTST'.
    itcpo-tdpreview = 'X'.
*   ENDIF.

  endif.

* Bei Probedruck, wenn das Medium keine Drucker ist.        " 361152

  if nast-sndex eq 'X' and nast-nacha ne '1'.               " 361152

    xdevice = 'PRINTER'.                                    " 361152

    if nast-ldest eq space.                                 " 361152
      xdialog = 'X'.                                        " 361152
    else.                                                   " 361152
      itcpo-tddest   = nast-ldest.                          " 361152
    endif.                                                  " 361152

  endif.                                                    " 361152

  itcpo-tdnoprint  = 'X'.
  itcpo-tdcover    = nast-tdocover.
  itcpo-tdcopies   = nast-anzal.

  if sy-ucomm eq 'DRPR' or                                  " 361152
     nast-sndex eq 'X'.                                     " 361152
    itcpo-tdnoprint  = ' '.                                 " 361152
    itcpo-tdnoprev   = 'X'.                                 " 361152
    itcpo-tdcopies = 1.
  endif.

  itcpo-tddataset  = nast-dsnam.
  itcpo-tdsuffix1  = nast-dsuf1.
  itcpo-tdsuffix2  = nast-dsuf2.
  itcpo-tdimmed    = nast-dimme.
  itcpo-tddelete   = nast-delet.
  itcpo-tdsenddate = nast-vsdat.
  itcpo-tdsendtime = nast-vsura.
  itcpo-tdprogram  = sy-repid.
  itcpo-tdnewid    = 'X'.                                   "99282

* Formular festlegen -------------------------------------------------*

  call function 'OPEN_FORM'

       exporting form = tnapr-fonam
                 language = ekko-spras
                 options = itcpo
                 archive_index  = p_toa_dara
                 archive_params = p_arc_params
*              ARCHIVE_PARAMS = ALARC_PAR1
                 device = xdevice
                 dialog = xdialog
             mail_sender        = lvs_sender
             mail_recipient     = lvs_recipient
       exceptions canceled = 01
                  device   = 02
                  others   = 03.

  if sy-subrc ne 0.
    p_retco = '1'.
    perform protocol_update using '142' ekko-ebeln space space space.
    exit.
  endif.

endform.                               " ZPREPARE_FORMULAR

*&---------------------------------------------------------------------*
*&      Form  ZENDE
*&---------------------------------------------------------------------*
*       copy from LMEDRUCKF1K form ENDE
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

form zende changing p_retco.

* Unterschrift -------------------------------------------------------*

  call function 'WRITE_FORM'
       exporting
            element = 'LAST'
       exceptions
            others  = 01.

  clear sy-subrc.

* Folgeseitenzaehler löschen -----------------------------------------*

  call function 'WRITE_FORM'
       exporting
            element  = 'NEXTPAGE'
            window   = 'NEXTPAGE'
            function = 'DELETE'
       exceptions
            others   = 01.

  clear sy-subrc.

* Ende Formulardruck --------------------------------------------------*

  clear i_otf[].

  call function 'CLOSE_FORM'
       importing
            result  = result
       tables
            otfdata = i_otf
       exceptions                                           "HW 205472
            others  = 1.                                    "HW 205472

  if not sy-subrc is initial.                               "HW 205472

    p_retco = '1'.                                          "HW 205472

    perform protocol_update using '142' ekko-ebeln
                                   space space space.       "HW 205472
    exit.                                                   "HW 205472
  endif.                                                    "HW 205472

  if result-tdspoolid ne space.
    spoolid = result-tdspoolid.
    perform protocol_update using '320' spoolid space space space.
  endif.

  if not result-tdfaxid  is initial or                      " 422131
     not result-tdmailid is initial.                        " 422131
    clear syst-msgv1.                                       " 422131
    if not result-tdfaxid is initial.                       " 422131
      syst-msgv1 = result-tdfaxid.                          " 422131
    elseif result-tdmailid is initial.                      " 422131
      syst-msgv1 = result-tdmailid.                         " 422131
    endif.                                                  " 422131

    call function 'NAST_PROTOCOL_UPDATE'                    " 422131

         exporting                                          " 422131
              msg_arbgb = 'VN'                              " 422131
              msg_nr    = '095'                             " 422131
              msg_ty    = 'I'                               " 422131
              msg_v1    = syst-msgv1                        " 422131
         exceptions                                         " 422131
              others    = 1.                                " 422131
  endif.                                                    " 422131

  if result-userexit eq 'C' or
      result-userexit eq 'E'.
    p_retco = '9'.
  endif.

* send mail with PDF attachment to distirbution list

  if nast-nacha eq '5'.

    perform f_send_mail changing p_retco.

  endif.

*---> End of Program

Notes:

Vendor set up:

Vendor (mail) with flag in ADR6-FLGDEFAULT is considered as the main e-mail.

Vendor (mail) with remark "Order" or "Orders" in screen field ADSMTP-REMARK are considered as the secondary e-mail.

Else are considered.

ABAP Tips

See Also
Extract the smtp email address

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP Basis, ABAP Programming and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.