Need to fix the clickable link to send email

Kaushik Ghosh
Tera Contributor

I need to fix a clickable link which was mentioned on a service portal page. The link is named as 'Send Report in Email', which is not working.

KaushikGhosh_0-1685073038733.png

 

 

 


Please find the code from the attachment. I have also shared the HTML of that portion. 

<script>
  // Move this code to client script.  
  function SendMail(strid)
  {
    var mailBody=document.getElementById(strid);
    var outlookApp = new ActiveXObject("Outlook.Application");
    var nameSpace = outlookApp.getNameSpace("MAPI");
    mailFolder = nameSpace.getDefaultFolder(6);
    mailItem = mailFolder.Items.add('IPM.Note.FormA');
    mailItem.Subject = "Problem Executive Summary Report - ";
    mailItem.To = "";
    mailItem.HTMLBody = mailBody.innerHTML;
    mailItem.display(0);  
  }
</script> <!-- Javascript code to email content of Div ID provided in function call -->
 
And
 
 <li class="showORhide" onClick="javascript&colon;SendMail('printView');">
              Send Report in Email
            </li>
 
Here I am attaching the code of the client Script. Could you please help to let me know why the highlighted link is not working.
2 REPLIES 2

Atul kumar
Tera Guru

The code you provided is using ActiveXObject, which is specific to Internet Explorer and older versions of Microsoft Office. It is not supported in modern browsers like Chrome, Firefox, or Edge. Therefore, the code will not work in most modern browsers.

If you need to send an email from a web page, you should consider using server-side code or a third-party email service provider that offers APIs. Here's an example of how you can achieve this using JavaScript and an email service provider's API:

```javascript
function sendMail() {
var mailBody = document.getElementById('printView').innerHTML;
var recipientEmail = 'recipient@example.com';
var subject = 'Problem Executive Summary Report';

// Make an API call to your server or use a client library for the email service provider
// Pass the mailBody, recipientEmail, and subject as parameters
// Example using a fictional email service provider called "EmailService"
EmailService.sendEmail(mailBody, recipientEmail, subject)
.then(function(response) {
// Handle success response
console.log('Email sent successfully:', response);
})
.catch(function(error) {
// Handle error
console.error('Error sending email:', error);
});
}
```

In this example, you would need to replace `EmailService` with the actual API client library or code provided by your chosen email service provider. You will also need to configure the email service provider with your credentials and email settings.

Regarding the HTML code, it seems fine, and the `onClick` event should trigger the `sendMail()` function. However, since the code inside the `sendMail()` function relies on unsupported ActiveXObject, it won't work as intended.

To make the highlighted link work, you need to update the code to use a different method for sending emails, such as the example provided above using a server-side solution or an email service provider's API.

Atul kumar
Tera Guru
function sendMail() {
  var mailBody = document.getElementById('printView').innerHTML;
  var recipientEmail = 'recipient@example.com';
  var subject = 'Problem Executive Summary Report';

  // Make an API call to your server or use a client library for the email service provider
  // Pass the mailBody, recipientEmail, and subject as parameters
  // Example using a fictional email service provider called "EmailService"
  EmailService.sendEmail(mailBody, recipientEmail, subject)
    .then(function(response) {
      // Handle success response
      console.log('Email sent successfully:', response);
    })
    .catch(function(error) {
      // Handle error
      console.error('Error sending email:', error);
    });
}