Sending e-mail to Internet e-mail addresses

In this recipe, we will see how we can modify the existing program so that, instead of the SAP user, we can send the same e-mail to an Internet address. We will make a copy of the same program and add additional code. The class that is to be used, in this case, is cl_bcs_cam_address (instead of the cl_sapuser_bcs class). The method create_internet_address will be used for creating Internet user addresses.

How to do it...

We will now see the changes we need to make to the given program:

  1. Instead of the myrecipient object reference being based upon the class cl_sapuser_bcs, we will use the class cl_cam_address_bcs.
    How to do it...
  2. Next, we will call the method create_internet_address of the cl_cam_addess_bcs class for creating an e-mail address.
    How to do it...
  3. We may remove the i_express parameter assignment from the add_recipient method call of the cl_bcs class (since the e-mail is going to an e-mail address outside the SAP system, pop-up express messages are irrelevant).
    How to do it...
  4. Next we define a reference to the interface if_sender_bcs for our e-mail address (that is, sender e-mail address).
    How to do it...
  5. An Internet address is created for our e-mail address using the same create_internet_address method of the cl_cam_address_bcs class. The created object is stored in the variable myemailaddress defined earlier.
    How to do it...
  6. Finally, the e-mail address is added as the sender of the send request using the set_sender method of the cl_bcs class.
    How to do it...
  7. The rest of the coding remains the same as in the previous recipe.

How it works...

We made a copy of the program in the previous recipe. The class cl_cam_bcs_address is used for defining the recipient user. Since we have the e-mail address of the recipient, we used the static method create_internet_address of the cl_cam_address_BCS class. The necessary recipient is returned because of the method call. This is later added to the send request, thus specifying the Internet address.

Once the COMMIT WORK statement is executed, the e-mail is sent to the Internet user address. In the receiver's inbox, we will see our e-mail address as the sender (since the set_sender method has been used).

How it works...

E-mail transfers are complicated. It may be possible that the programming done is correct but the e-mails are not sent. From experience, many times the problems arising when testing programmatic e-mail sending are e-mail server configuration/routing problems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.97.85