Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Sending mails from 2 SMTP servers

0 Kudos
5,812

In our company we have two SMTP servers configured for sending mails. One server for sending mails within the company and the other one for sending external mails. We have configured two SMTP nodes SMTP1 and SMTP2 in tcode SCOT. All internal mails send from sap should route through SMTP1 and external mail through SMTP2. This means all mails sending with in the company should be send from the SMTP server configured in the SMTP1 and external mails should send from SMTP server configured in SMTP2.

In ABAP, we use CL_BCS classes for sending mail. But, in any of the BCS classes methods we used, we cannot find an area where we can mention the SMTP node to be used for sending mail. If somebody knows, please help.

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Kudos
4,853

Usually you define such rule/behavior in SCOT transaction, 'Address area' - 'Routing', not during the generation of mail (using to address area and sender group CDG)

If you actually want to play with those rules, look a FM SX_NODE_ID_DETERMINE (at your own risk) for implicit enhancements...

20 REPLIES 20
Read only

joltdx
Active Contributor
4,853

Hi!

Based on what you describe, I would not try to do that in code at all.

Instead, this should be system config in SCOT. On the nodes, there are settings for address types, which has settings for address area. That's where the filtering should be done. Talk to your Basis people... 🙂

Read only

4,853

I follow jorgen_lindqvist41 (as always), this is SCOT customizing, not code. Otherwise you will have to use real good coding to not have dependencies on the SMTP node name ..

Read only

0 Kudos
4,853

Thank for the reply.

But I think the mentioned address area is for filtering recipient address only. For example, if I want to use the node SMTP1 to send mails to @gmail.com ids only, I can give that filter in the address area of SMTP1.

But my requirement is to filter the SMTP server (Outgoing mail server) to be used for sending the mail. I want to specify the SMTP server to be used when sending the mail.

Read only

joltdx
Active Contributor
4,853

I'm not aware of any way to do that in code.

Read only

0 Kudos
4,853

nop, SCOT filter the outgoing email never the incoming email.

If you want to filter incoming email you have to customize the STMP server

Read only

0 Kudos
4,853

frdric.girod

My problem in related to outgoing emails and not incoming emails. I want to programmatically (conditionally) switch between SMTP servers while sending mail. Certain set of mails with a specific from address (sender address) I want to send through one SMTP node. Another set of mails with a another sender address I want to send through the other SMTP node. Now I can do it manually by taking tcode SCOT and put * in address area of the required SMTP node every time I send a mail.

Read only

4,853

I have checked little bit, and I think it could not be possible directly when you create an email. The choice of the node is done when you send it : transaction SOST.

So ... you will create your ZSOST ?

or let SCOT do his job ?

Read only

RaymondGiuseppi
Active Contributor
0 Kudos
4,854

Usually you define such rule/behavior in SCOT transaction, 'Address area' - 'Routing', not during the generation of mail (using to address area and sender group CDG)

If you actually want to play with those rules, look a FM SX_NODE_ID_DETERMINE (at your own risk) for implicit enhancements...

Read only

0 Kudos
4,853

Thank you raymond.giuseppi.

I tried sending mail with CL_BCS class routines and using FM SO_NEW_DOCUMENT_ATT_SEND_API1. But the FM SX_NODE_ID_DETERMINE is not triggered in both cases. So I don't find any use in enhancing it. Do I need to follow some other method for sending mail.

Read only

0 Kudos
4,853

lijujohn Always use BCS to send emails (SO_* function modules are deprecated). For information BCS is a wrapper of the old code behind these function modules.

Read only

0 Kudos
4,853

I use BCS only. But need a way to specify the SMTP node (outgoing server) to be used for sending each mail. Giving filter in SCOT helps only to redirect mails based on TO address. I want filter based on from address.

Read only

4,853

This FM is not triggered in the programs that create the mail (this is not the correct place for this) but in the program that actually transfer the mail to the mail server. (Check scheduled job in SCOT)

Read only

0 Kudos
4,853

Thanks for the reply raymond.giuseppi

You are right. The FM is triggered when calling the program RSCONN01 which is scheduled in background. In the FM, by debugging, when I change the node_id at the last point, it is working. There is an enhancement point also. But could not find any information, precisely the sender (From) address, which is useful for redirecting the mail to different SMTPs. I want the sender email id of the mail at that point. Only basic information like To Address is available there. Any way to get other details of the mail at this point?

Read only

4,853

Why do you want the sender mail now, your initial requirement was for the to mail address (in/out company)

If you actually changed your requirement, go back to another solution using sender group (parameter id CDG) and link those to different SMTP node in SCOT.

Read only

0 Kudos
4,853

Thanks raymond.giuseppi


I think, assigning a CDG parameter for a set of users in SU01 and linking that CDG parameter to a particular SMTP node in SCOT will help to redirect mails from these set of users through that SMTP node. But my requirement is to redirect mails to different SMTPs based on the FROM address set in the sending mail and not the SAP Login ID. The FROM address is usually set in the sending mail using

CALL METHOD cl_cam_address_bcs=>create_internet_address
EXPORTING
i_address_string = sendermailid
i_address_name = sendermaildescription
RECEIVING
result = wa_sender.

CALL METHOD send_email->set_sender
EXPORTING
i_sender = wa_sender.

The sendermail and sendermaildescription that we set here will be shown in the inbox of the receiver. I want to redirect outgoing mails based on the above sendermailid. Enhancing the FM SX_NODE_ID_DETERMINE you suggested will serve the purpose. But the values of the above sendermailid of the outgoing mail is not available here. Only basic data like TO address is available here. If there is any way to get sendermailid, please share. Or I need a variable/value that can set in the CL_BCS class level which can be accessed in the FM SX_NODE_ID_DETERMINE.

Read only

4,853

Got a variable that holds id of the SENDER which seems to be unique for combination of sending address and name. Not sure whether it is reliable. Thanks raymond.giuseppi for the help.

Read only

0 Kudos
4,853

Hi, lijujohn,

I have the same requirement, can you, please, navigate me, where did you find the information to evaluate SMTP node based on sender address?

Thanks

Read only

周建华
Participant
0 Kudos
4,853

sender = cl_sapuser_bcs=>create( mailfrom ). "user ID from SAP

su01 set CDG

SPAN { font-family: "新宋体"; font-size: 10pt; color: #000000; background: #FFFFFF; }.L0S31 { font-style: italic; color: #808080; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }.L0S70 { color: #808080; }

Read only

BrettJhonson
Discoverer
0 Kudos
4,275

In SCOT, use 'Address area' for routing rules to differentiate between SMTP servers. Alternatively, enhance FM SX_NODE_ID_DETERMINE for more control over sender address-based routing using SMTPget.

Read only

BrettJhonson
Discoverer
0 Kudos
4,082

To route emails via different SMTP nodes in SAP using CL_BCS:

  1. Configure SCOT:

    • Create two SMTP nodes: SMTP1 for internal mails, SMTP2 for external mails.
    • Set routing rules: Internal (*@yourcompany.com) via SMTP1, External (*@*) via SMTP2.
  2. Use CL_BCS:

    • Create and configure the send request with CL_BCS.
    • Add recipients and set the sender.
    • Send the email. SCOT routing rules will determine the correct SMTP node.
  3. Find the best SMTP server service from SMTPget