cancel
Showing results for 
Search instead for 
Did you mean: 

Raise Alert with HTML and add attachments

0 Kudos
673

Hi SAP Community,

I'm using raise alert function to notify user, the body of the email will be in HTML format, specifically a html table. Is it possible to use the raise alert function to send email with html body as the content.

Been trying but the email won't parse the html tags. Is there any way to overcome this issue. Using outlook app is not possible since our client didn't allocate any outlook license for the email and only provide the email with smtp.

Also if could is it possible to add an attachment for the email using the raise alert function.

Thanks and Regards,

Nael

Accepted Solutions (0)

Answers (3)

Answers (3)

chwostian
Participant

Hi Nael,

To the best of my knowledge the answer is NO. If you want to use your alerter as a notifier then you are stuck with the standard functionality.

But I see another approach here:

- you use your alerter to notify of CF or agent events (in this case you use only simple text messages),

- for all other situations you can use some scripting solution like vbscript or node.js combined with execute command activity (you can use it to send standard html messages or report errors that you catch and process in your automation).

For vbscript I suggest you visit this page https://www.rondebruin.nl/win/s1/cdo.htm for more details. Test it first from within excel. I have just done it and it works. I also tested authentication by providing user and password. It does send html messages and this is fast. A lot faster than outlook. I haven't tested sending attachments but I am positive it will work.

Here's a list of steps you need to follow:

- create a vbs script file that takes arguments,

- add it to your project

- read its absolute path at run time

I suggest moving it to a different location to make sure its path does not exceed the path length the wscript allows (I am not sure about this one but I remember I had I had some issues). I chose my path to be C:\\Temp

- and now you can use execute command activity

you need to now concatenate your params. In your case your params could be like SMTPServer, PORT, SenderAddress, Recipient, PathsToYourAttachments, User and Password and so for and so forth.

Let me know if this solves your query or you get stuck with the solution I described above. If you get stuck I'll create a blog with a full solution.

Nevertheless let's ask an expert here if there are any other less sophisticated solutions (however I think this is quite easy and straightforward) but against low-code approach. jleonard hi Julien could you chip in on that? Any suggestions? Or perhaps we're missing something here that is right there in front of us. Thanks:)

0 Kudos

Hey Jakub,

Sorry for the late response on this matter,

I find that your way is the simplest approach to solve the matter. Truly needing to use the vbscript to send out email is quite unpractical since we are unable to utilize the SAP tools that are available. But the script works a charm! just that if any errors thrown I haven't come out a way to capture it back.

Regards,

Nael

chwostian
Participant
0 Kudos

amin_omidy have you really tried this one in SAP iRPA? You can't add an external library in the custom script. Lately we have had a discussion with one of the consultants about it. The working idea is to add a full library (nodemailer in your case) to your project and then try to use "require" at the top of the script and see if this works. If it doesn't similar approach like mine with vbscript.

Can you elaborate on your solution? Thanks.

Amin_Omidy
SAP Champion
SAP Champion
0 Kudos

You can use the raise alert function to send an email with an HTML body as the content, but it requires some additional configuration or coding.

  1. To send an email with an HTML body, you will need to set the email message's body format to HTML. This can typically be done by setting the appropriate property or parameter of the raise alert function or the email library you are using.
  2. To include HTML tags in the email body, you will need to make sure that the tags are properly encoded and that the email client is configured to display HTML content.
  3. As for the attachment, it is also possible to add an attachment to the email using the raise alert function, you will need to provide the path to the attachment file and set the appropriate property or parameter to indicate that the email should include an attachment.

A simple code example of how you can send an email with an HTML body and an attachment using the popular Nodemailer library for Node.js which you can covert the code to other languages too :

const nodemailer = require('nodemailer');
lettransporter = nodemailer.createTransport({
host: 'smtp.example.com',
port: 587,    
secure: false,    
auth: {        
user: 'username',        
pass: 'password'    
}
});
let mailOptions = {
from: 'sender@example.com',
to: 'recipient@example.com',    
subject: 'Email with HTML body andattachment',
text: 'Hello, this email includes an HTML body and an attachment',
html: '<h1>Hello</h1><p>This is an example of an email with an HTMLbody.</p>',    
attachments: [        
{            
filename: 'attachment.txt',            
path: '/path/to/attachment.txt'        
}    
]};
transporter.sendMail(mailOptions,(error, info) => {    
if (error) {        
console.log(error);    
} else {        
console.log('Email sent: ' +info.response);    
}
});

Note:

The “nodemailer.createTransport” function is used to create an SMTP transport for sending email.

The transporter.sendMail() function uses the SMTP (Simple Mail Transfer Protocol) to send the email. It connects to the specified SMTP server using the provided authentication credentials and sends the email to the specified recipient.

The attachments property of the “mailOptions” object is used to include an attachment in the email. The filename property specifies the name of the attachment file as it should appear in the email, and the path property specifies the location of the file on the file system. You can add multiple attachments by adding more objects to the attachments array.

Hope this helps