[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
3. Once in there, click the Open Activity List Button
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
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
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.
8. In the EMail field, fill it with an email using the declared domain, click finish.
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.
Thanks Melvin, for sharing this information here.
Andreas
Thanks for your comment Andreas, glad to help!
Would be great if you could a link to the script example or the script itself.
Hi Christian, I already updated the post with the script itself, hope it will be useful for anybody! 😀
Very useful... Thanks!
Hi Melvin,
Thanks for sharing this information.can you share how to send the email from travel on demand.
Hi Melvin, thanks for this tutorial it helped me a lot! Do you also have experience sending HTML emails?
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
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)
@Alessandro, thanks .. But can you elaborate your ans plz.
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!
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
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?
you can change the email settings from the business configuration if I remember correctly
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
Wow. Thanks for your effect @hanu, @Alessandro. Thanks a lot. I got an answer as like I expected. 🙂
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!
HTML custom email notifications in SAP Cloud Applications Studio
try this
@Alessandro, thanks a lot.
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:
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
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:
Please guide.
Thanks,
Sri
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:
Hi  Melvin,
Could you please notice me if you update the function.
Thanks,
Qiang.
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.
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
Hello,
Please note that the BO EmailActivity is only depreciated in C4C systems and not in Business ByDesign systems.
with kind regards,
Kathrin