You need to sign in to do that
Don't have an account?

How i can send mail with attachment with javascript in visualforce
I trying to send email with attachment in javascript but i can't, somebody help me.

I don't know what is the problem.
Thanks!
sforce.connection.sessionId = '{!$Api.Session_ID}'; var oppId = document.getElementById('{!$Component.page.form.oppId}'); var query = "SELECT Account.Email__c FROM Opportunity WHERE Id = '" + oppId.value + "'"; var record = sforce.connection.query(query); record = record.getArray('records'); var singleRequest = new sforce.SingleEmailMessage(); var fileAttachment = new sforce.EmailFileAttachment(); singleRequest.subject = 'Test Mail'; singleRequest.toAddresses = record[0].Account.Email__c; singleRequest.optOutPolicy = 'FILTER'; singleRequest.plainTextBody = j$('#textArea').val(); fileAttachment.Body = new Blob([bodyAttachment],{ type: 'application/pdf'}); fileAttachment.ContentType = 'application/pdf'; fileAttachment.FileName = name + '.pdf'; fileAttachment.Inline = false; console.log(fileAttachment); singleRequest.fileAttachments = ([fileAttachment]); var sendMailRes = sforce.connection.sendEmail([singleRequest]);
I don't know what is the problem.
Thanks!
Just set the body to be "test 123" and see if it goes.
[1] http://salesforce.stackexchange.com/questions/64299/save-attachment-with-remote-objects
[2] http://salesforce.stackexchange.com/questions/34405/js-synchronous-calls-email-with-attachment
But when i try to attach file to Single Email Messenge i have error which I have said above, I think that it is possible to do because only attachment it's problem. When i try to send whitout attachment email is sent.
Did you ever get this to work? I'm trying to do the same.
I also tried to use your code to create the attachement - but having trouble with this line: var oppId = document.getElementById('{!$Component.page.form.oppId}');
Can youy tell me what Id it is referencing?
-thanks,
Michael