Skip to Content
Author's profile photo Melvin Hidalgo

[Tutorial] Sending Emails from ByD

 

EDIT – 2017-05-10

The scripting mentioned below seems to be now reprecated, however using the Platinum Engineer library seems that SAP has made it even simpler, I’m attaching the screen capture of the method itself, which I haven’t tried yet, but as soon as I do I’ll update you on this post:

 

Seems to be easier, isn’t it?

 

I’m leaving the original post as is, just for documentation reference.

 

 

Hi people, there’s a guide explaining the configuration needed to send an email from the internal Mail service included in ByD.

 

1. First of all, we need to create a domain, so access the ByD as a key User.

 

2. Then access the Business Configuration > Implementation Projects

Captura.PNG

 

3. Once in there, click the Open Activity List Button

 

Captura1.PNG

 

4. Then go to the fine tuning tab, and in the search field type “Mail”, select the Mail and Fax Configuration, and click the “Open” Button

Captura3.PNG

 

5. A new window will appear, Click the Email and Fax Settings link.. then..

 

6. In the Allowed Sender E-Mail Domains, click add, and write any domain, in this case my domain is HiByDCommunity.com

and leave the other fields as my caption, click save and close

 

Captura4.PNG

 

 

7. Now we’re going to configure our personal Mail, based on the domain that we just added.

Go to the Home WorkCenter, and select the Self Services Overview, Inside the Company Address Book block, click the Edit my Contact Data Link.

 

capture.PNG

 

8. In the EMail field, fill it with an email using the declared domain, click finish.

caption2.PNG

 

Now we are ready to test this up.

 

Use the script example in the PSM, in the EMail Activity section!

 

 

UPDATE:

 

Many of you asked for the script to implement this, so there you go! 😀

 

On this example I created the QA with three input fields, 1 for the email title, another for the email where you want to send the message, and another with the actual message.

 

 

import ABSL;

import AP.FO.Activity.Global;

 

//EmailActivity: Root node

var elEmailRoot :  elementsof EmailActivity;

var instEmail;

 

// EmailActivity: define party node

var elEmailParty : elementsof EmailActivity.Party;

var instParty;

 

 

var TXT_TYPE_BODY_TEXT = “10002”;

var elEmailTxtCollTxt:      elementsof EmailActivity.TextCollection.Text;

var elEmailTxtCollTxtCntnt: elementsof EmailActivity.TextCollection.Text.TextContent;

var instEmailTxtColl;

var instEmailTxtCollTxt;

 

 

elEmailRoot.Name.content = this.asunto; //Here comes the title of the email

 

 

 

instEmail = EmailActivity.Create(elEmailRoot);

 

 

 

elEmailParty.PartyKey.PartyID.content = this.email.content;         //The email address where you want to send it

instEmail.MessageToParty.Create(elEmailParty);

 

 

instEmailTxtColl = instEmail.TextCollection.Create();

elEmailTxtCollTxt.TypeCode.content = TXT_TYPE_BODY_TEXT;

instEmailTxtCollTxt = instEmailTxtColl.Text.Create(elEmailTxtCollTxt);

elEmailTxtCollTxtCntnt.Text.content = this.contenido; //                           Here the message itself

instEmailTxtCollTxt.TextContent.Create(elEmailTxtCollTxtCntnt);

 

instEmail.Send();

 

Update: This script must have the save after execution indicator marked as true.

Assigned Tags

      26 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Andreas Eissmann
      Andreas Eissmann

      Thanks Melvin, for sharing this information here.

      Andreas

      Author's profile photo Melvin Hidalgo
      Melvin Hidalgo
      Blog Post Author

      Thanks for your comment Andreas, glad to help!

      Author's profile photo Christian Happel
      Christian Happel

      Would be great if you could  a link to the script example or the script itself.

      Author's profile photo Melvin Hidalgo
      Melvin Hidalgo
      Blog Post Author

      Hi Christian, I already updated the post with the script itself, hope it will be useful for anybody! 😀

      Author's profile photo Former Member
      Former Member

      Very useful... Thanks!

      Author's profile photo Former Member
      Former Member

      Hi Melvin,

          Thanks for sharing this information.can you share how to send the email from travel on demand.

      Author's profile photo Former Member
      Former Member

      Hi Melvin, thanks for this tutorial it helped me a lot! Do you also have experience sending HTML emails?

      Author's profile photo Sankaran Angamuthu
      Sankaran Angamuthu

      hi i followed this script. But I get an bellow error. what is this error mean?

      Mailing not possible; e-mail address does not exist for sender 8000000165

      Author's profile photo Alessandro Iannacci
      Alessandro Iannacci

      you need to add the email address for the sender that you are using (for the username that you are using to run the script)

      Author's profile photo Sankaran Angamuthu
      Sankaran Angamuthu

      @Alessandro, thanks .. But can you elaborate your ans plz.

      Author's profile photo Sankaran Angamuthu
      Sankaran Angamuthu

      Thanks Alessandro. Issue Solved. I have filled my E-mail id in service agent. so now mail will go through my default E-mail id.  Can you suggest script for assigning username in program itself!

      Author's profile photo Hanumath Kanamarlapudi
      Hanumath Kanamarlapudi

      Hi Sankaran,

      Following is the code for to fill the user email address and email it to user from SDK

      //Elements of Email

      var emailActivityElements : elementsof EmailActivity;

      var emailActivityMessageFromPartyElements : elementsof EmailActivity.Party;

      var emailEmployeeResponsiblePartyElements : elementsof EmailActivity.Party;

      var emailActivityCC : elementsof EmailActivity.Party;

      var emailAcitivtyTo : elementsof EmailActivity.Party;

      var emailActivityEmailActivity : elementsof EmailActivity.Party;

      var emailActivityTextCollText : elementsof EmailActivity.TextCollection.Text;

      var emailActivityTextCollTextTextCont : elementsof EmailActivity.TextCollection.Text.TextContent;

      var employeeMailID;

      var employee;

      var employeeAdminMailID;

      var emailActivityInstance;

      employee = Employee.Identification.Retrieve(notification.Source);

      if (employee.IsSet())

      {

          if (employee.ToParent.CurrentDefaultEmployeeWorkplaceAddressInformation.IsSet())

          {

              var employeeWorkPlaceAddressInfo = employee.ToParent.CurrentDefaultEmployeeWorkplaceAddressInformation;

                if (employeeWorkPlaceAddressInfo.EmployeeWorkplaceAddressWorkplaceAddress.IsSet())

                {

                      employeeMailID = employeeWorkPlaceAddressInfo.EmployeeWorkplaceAddressWorkplaceAddress.DefaultEMail.URI.content;

                }

            }

      }

          //For display the subject accordingly

        

              emailActivityElements.Name.content = "Reg: Test Email";

              emailActivityInstance = EmailActivity.Create(emailActivityElements);

          // for assigning the To Party

          if (!employeeMailID.IsInitial())

          {

              emailAcitivtyTo.PartyKey.PartyID.content = employeeMailID;

              emailActivityInstance.MessageToParty.Create(emailAcitivtyTo);

          }

          else

          {

              raise Error/Info Messgaes accordingly

          }

          //TextCollectionTextTypeCode 10002 -> Body Text

          var TxtTypeCode = "10002";

          var emailActivityTxtCollIns = emailActivityInstance.TextCollection.Create();

          emailActivityTextCollText.TypeCode.content = TxtTypeCode;

          var emailActivityTxtCollTxtIns = emailActivityTxtCollIns.Text.Create(emailActivityTextCollText);

         

          //To Display the Message Note

               

              emailActivityTextCollTextTextCont.Text.content = "Dear Recipient," + "\n \n" +

              "Text Needed ";

          }

          var emailActTxtCollTxtTxtCont = emailActivityTxtCollTxtIns.TextContent.Create(emailActivityTextCollTextTextCont);

          //If Instance is Set then Send the mail

          if (emailActivityInstance.IsSet())

          {

              emailActivityInstance.Send();

          }

      Please try this and this should work.

      Regards

      Hanu

      Author's profile photo Sankaran Angamuthu
      Sankaran Angamuthu

      Hi hanumanth, very  much happy to see your reply. Yep I got an answer. That's not a matter.  A mail has been triggered successfully. But I need to specify my 'From address' as like 'To addres' in my coding. I think, in your script, 'from address' is static, which ll take service agent mail Id. In above coding, yu declared 'var employeeAdminMailID'. But whr did you use it! Kindly suggest any script is there to specify From address in scripting?

      Author's profile photo Alessandro Iannacci
      Alessandro Iannacci

      you can change the email settings from the business configuration if I remember correctly

      Author's profile photo Hanumath Kanamarlapudi
      Hanumath Kanamarlapudi

      Hi Sankaran,

      // Email: Organizer party - mandatory

      if (! emailActivityInstance.MessageFromParty.IsSet())

      {

        emailAcitivtyTo.PartyKey.PartyID.content = "Sender Email as required";

      emailActivityInstance.MessageFromParty.Create(elEmailParty);

      }

      Hope this should work

      Regards

      Hanu

      Author's profile photo Sankaran Angamuthu
      Sankaran Angamuthu

      Wow. Thanks for your effect @hanu, @Alessandro. Thanks a lot. I got an answer as like I expected. 🙂

      Author's profile photo Sankaran Angamuthu
      Sankaran Angamuthu

      Hi,

      How to attach, html tags in message content. I planned to send attractive mail to the user. That's why I tried with HTML tags. I have normally typed html tags within double codes in msg content variable. But it will print as it is, in email . Anyone help me to send an email with HTML tags. Thanks!

      Author's profile photo Alessandro Iannacci
      Alessandro Iannacci
      Author's profile photo Sankaran Angamuthu
      Sankaran Angamuthu

      @Alessandro, thanks a lot.

      Author's profile photo Deepthi Manjunath
      Deepthi Manjunath

      Hi,

      I have added the above script in the 'BeforeSave' of a custom BO, which has a web service.  When I call this web service, I expected the script will send an email.  However, I am getting this error in Dump Analysis:

      08:29:29 _1000015 No access possible via a 'NULL' data reference. Y00RKLIIY_ /Y00RKLIIY_MAIN/SRC/ErrorHandlingBO-Root-Event-BeforeSave.absl 63 40

      Line no. where the above error is occurring is at:

      instEmail.MessageToParty.Create(elEmailParty);

      When calling the web service itself, it throws the below error:

               <env:Reason>

                  <env:Text xml:lang="en">RABAX occurred on server side</env:Text>

               </env:Reason>

               <env:Detail>

                  <sap:Rabax xmlns:sap="http://www.sap.com/webas/710/soap/runtime/abap/fault/generic">

                     <SYDATUM>20160906</SYDATUM>

                     <SYUZEIT>072928</SYUZEIT>

                     <ERRORCODE>DATREF_NOT_ASSIGNED</ERRORCODE>

                  </sap:Rabax>

               </env:Detail>

      Can you please advise what I am doing wrong here, I have copy/pasted the above code?

      Thanks in advance,

      Deepthi

      Author's profile photo Former Member
      Former Member

      Hi All,

      Since the EmailActivity is now deprecated, I am trying to make use of Activity BO to perform send mail, but could not achieve the same. i have these points unanswered:

      1. Without creating instance in Activity can I send the mail when Outlook is not configured?
      2. In Activity BO, Party.EmailURI is read only what can be done to specify the sender?

      Please guide.

      Thanks,

      Sri

      Author's profile photo Melvin Hidalgo
      Melvin Hidalgo
      Blog Post Author

       

      SRI,

      Yes this guide is now deprecated, however using the Platinum Engineering seems to be a new function and looks pretty straight forward for me, I haven't yet used it, but as soon as I do I'll update it here.

      I'm attaching a screenshot of the function itself:

      Author's profile photo Former Member
      Former Member

      Hi  Melvin,

      Could you please notice me if you update the function.

      Thanks,

      Qiang.

      Author's profile photo Melvin Hidalgo
      Melvin Hidalgo
      Blog Post Author

      Former Member

      I have added a new post within my blog, please check it out.

      As soon as it gets approved I'll pass you the link here.

       

      Author's profile photo Melvin Hidalgo
      Melvin Hidalgo
      Blog Post Author

      Qiang,

      I made a new post in my blog about these new actions, please make sure you check it out.

      I think it will help you

      Author's profile photo Kathrin Dietrich
      Kathrin Dietrich

      Hello,

      Please note that the BO EmailActivity is only depreciated in C4C systems and not in Business ByDesign systems.

      with kind regards,

      Kathrin