Forum Discussion

mustafayol's avatar
mustafayol
Contributor
3 years ago

Sending emails to multiple receipents with built-in SendMail function

hi,

 

I am using testcomplete's built-in SendMail function to send emails via the scripts.

SendMail(ToAddressFromHostFromNameFromAddressSubjectBodyFileName1, FileName2..FileNameN);

The problem is when I write more than one email to ToAddress section it fails.

 

According to documentation; "You can specify several addresses separated by commas or semicolons."

I tried to write recipient's emails by using separation methods as "," or ";" or "\," or "\;",

 

let ToAddress = "receipent1@company.com , receipent2@company.com" ;

let ToAddress = "receipent1@company.com"+ "," +"receipent2@company.com" ;

let ToAddress = "receipent1@company.com"+ ";" +"receipent2@company.com" ;

let ToAddress = "receipent1@company.com ; receipent2@company.com" ;

 

When I send an email to one recipient it works.


function send_Mail() {

SendMail("receipent1@company.com ", "smtp.companyhost.com", "FromSenderTester", "senderEmail@company.com", "Subject test email", "Body Test email")

}

But when I try to send it to more than one recipient it fails. 
Not Work!

function send_Mail() {

SendMail("receipent1@company.com , receipent1@company.com", "smtp.companyhost.com", "FromSenderTester", "senderEmail@company.com", "Subject test email", "Body Test email")

}

https://support.smartbear.com/testcomplete/docs/reference/program-objects/builtin/sendmail.html

 

2 Replies

  • you will need to make an array of the recipients list, and loop over that list sending the emails to each recipient one by one using the same function.

    • mustafayol's avatar
      mustafayol
      Contributor

      Hi Justin,

       

      Thanks for the reply. In fact, that's what I already do. But according to documentation, sending to multiple emails by separating commas or semi-columns should also be possible.

       

      let receipents = ["user1@gmail.com", "user2@gmail.com", "user3@gmail.com"];

      receipents.forEach(

      function sendMultiple(item) {SendMail(item, "smtp.companyhost.com", "FromSenderTester", "senderEmail@company.com", "Subject test email", "Body Test email")};

      );

       

      Best regards

      Mustafa