Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Add to additional Cc E-mail addresses with javascript.

Avatar

Level 9

I have figured out the script to send an e-mail based on a drop-down object but I need to also Cc two other people on that same email based on those users entering their email addresses on the form in two seperate textfields named, "CC-EmailAdrress1" and "CC-EmailAddress2". How can this be done?

Here's the script I am using so far"

var vEmail;

if (txtToAddress.rawValue !== null) {
     vEmail = txtToAddress.rawValue;
}


event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=MAR Assignment",cSubmitAs:"PDF",cCharset:"utf-8"});

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Don,

If you look at the email line of script, you will see that I am adding the CC variable at the END of the cURL string.

event.target.submitForm({cURL:"mailto: "+ vEmail +"?subject=" + vSubject +"&body=" + vBody + vCC,cSubmitAs:vFormat,cCharset:"utf-8"});

vCC is put at the end of the mailto string because it starts with an "&cc=", which is missing from my script above. (in my defense I was scripting on the side of the road, from memory )

// Declare the variable

var vEmail;

var vCC = "";

// Check that the email field is not null

if (txtToAddress.rawValue !== null) {

     vEmail = txtToAddress.rawValue;

}

// Look at cc fields over three if statements

if (ccEmail.rawValue !== null){

     vCC = "&cc=" + ccEmail.rawValue + ";";

}

if (ccEmail.rawValue !== null && MEAdminEmail.rawValue !== null){

     vCC = vCC + MEAdminEmail.rawValue;

}

else if (ccEmail.rawValue === null && MEAdminEmail.rawValue !== null)  {

     vCC = "&cc=" + MEAdminEmail.rawValue;

}

// Send email

event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=MAR Assignment" + vCC,cSubmitAs:"PDF",cCharset:"utf-8"});

That should work,

Niall

View solution in original post

6 Replies

Avatar

Level 10

Hi Don,

See here, third button down. Look at how I declare and set a vCC variable and where I use it in the email script.

http://assure.ly/eUR4wJ.

Niall

Avatar

Level 9

I had looked at that script before I posted my problem. the part I just can't get is how to have it use two Cc addresses, one in one textfield and one in another textfield. Can't get it to work.

Avatar

Level 10

Hi Don,

I can't do up an example, but the approach would be test that first field is not null and then set the value of the variable. Then test second field and if not null ADD it to the variable.

Something LIKE this

var vCC = "";

if (textfield1.rawValue !== null) {

vCC = textfield1.rawValue + "; ";

}

if (textfield2.rawValue !== null) {

vCC = vCC +textfield2.rawValue;

}

Then use the vCC variable in the same place in the email script as the example.

Niall

Avatar

Level 9

I have two textfields for the two Cc email addresses. When I click the button, the Cc addresses end up after the subject. What do I have wrong? 

// Declare the variable
var vEmail;
var vCC = "";

// Check that the email field is not null
if (txtToAddress.rawValue !== null) {
     vEmail = txtToAddress.rawValue;
}
if (ccEmail.rawValue !== null){
vCC = ccEmail.rawValue + ";";
}
if (MEAdminEmail.rawValue !== null){
vCC = vCC +MEAdminEmail.rawValue;
}

// Send email
event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=MAR Assignment" + vCC,cSubmitAs:"PDF",cCharset:"utf-8"});

Avatar

Correct answer by
Level 10

Hi Don,

If you look at the email line of script, you will see that I am adding the CC variable at the END of the cURL string.

event.target.submitForm({cURL:"mailto: "+ vEmail +"?subject=" + vSubject +"&body=" + vBody + vCC,cSubmitAs:vFormat,cCharset:"utf-8"});

vCC is put at the end of the mailto string because it starts with an "&cc=", which is missing from my script above. (in my defense I was scripting on the side of the road, from memory )

// Declare the variable

var vEmail;

var vCC = "";

// Check that the email field is not null

if (txtToAddress.rawValue !== null) {

     vEmail = txtToAddress.rawValue;

}

// Look at cc fields over three if statements

if (ccEmail.rawValue !== null){

     vCC = "&cc=" + ccEmail.rawValue + ";";

}

if (ccEmail.rawValue !== null && MEAdminEmail.rawValue !== null){

     vCC = vCC + MEAdminEmail.rawValue;

}

else if (ccEmail.rawValue === null && MEAdminEmail.rawValue !== null)  {

     vCC = "&cc=" + MEAdminEmail.rawValue;

}

// Send email

event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=MAR Assignment" + vCC,cSubmitAs:"PDF",cCharset:"utf-8"});

That should work,

Niall

Avatar

Level 9

That's what I needed! You're the best, thanks!

~Don