function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Federico LarsenFederico Larsen 

send mail through S-Control

Hi there,

I tryied this code to send an Email from a S-Control using the Toolkit AJAX, but even though the EmailMessage is created an associeted with the case, the Email is not processed by the Salesforce mail Server, so the Email Message appears like Sent but is Not.

function sendMail(){
setMsg("Sending Email Message...");
var ts = sforceClient.GetServerTimestamp().timeStamp;
_mail = new Sforce.Dynabean("EmailMessage");
_mail.set("FromAddress", "anyadress@myserver.com");
_mail.set("FromName", "Any Name");
_mail.set("HasAttachment", false);
_mail.set("Incoming", false);
_mail.set("MessageDate", ts);
_mail.set("ParentId", caseId);
_mail.set("FromName", "Any Name");
_mail.set("Subject", "Any Subject");
_mail.set("TextBody", "test envio from sforce-control\ntest envio from sforce-control\ntest envio from sforce-control");
_mail.set("ToAddress", "marcelo@virtualcompanyservices.com");
_mail.set("BccAddress", "federico.larsen@gmail.com");

sforceClient.Create([_mail], mailCallback);
}

function mailCallback(saveResult) {
if (saveResult[0].success == true) {
setMsg("Sending Mail. OK");
closeReload();
} else {
setMsg("Error sending mail: " + saveResult[0].errors[0].message);
}
}


Thanks a lot in advance for your help.

Federico.-
DevAngelDevAngel
Creating a record in the system does not trigger the sending of an email. As a matter of fact, I'm willing to bet that the email is created and sent before the email record is created and saved.
Federico LarsenFederico Larsen
Thanks Dave for your fast replies!

Ok, I understand that and I am agree.

So, How would you send an Email from a S-Control?

Thanks in advance for your help
DevAngelDevAngel
I don't know. Take a search through the boards. I think there was a hearty discussion on this topic previously.

In general, since we don't provide a "method" or api interface for sending an email you are tasked with trying to do it from js. This can be done if you use outlook and an activex control from your js, but requires a bit of overhead for browser trust etc.
Federico LarsenFederico Larsen
Ok, thanks again Dave.

I was tyring to do it in a api-friendly way, but now you said so, I will try to find another way, maybe using /email/author/emailauthor.jsp

Thanks a lot for your information.

Federico.-
DevAngelDevAngel
Sure no problem. One of the issues around doing emails from the api is that it exposes us to exploitation by spammers or other nefarious individuals. Anytime you provide a way to automate email generation you run the risk of abuse and we would rather not be exposed that way.