You need to sign in to do that
Don't have an account?
Email attachment just sending the link and asking password userid when trying to open
Messaging.SingleEmailMessage[] emails =new List<Messaging.SingleEmailMessage>();
//List<Contact> lstContacts=[Select Id,EMail FROM Contact WHERE EMAIL!=null];
for(Contactcont :lstContacts) {
Blob b =null;
Pagereference page =new Pagereference('/' + 'apex/OpportunityReport?cid='+cont.Id );
page.setRedirect(true);
Messaging.SingleEmailMessage mail =newMessaging.SingleEmailMessage();
String [] toAddresses =newString[] {email};
mail.setToAddresses(toAddresses);
mail.setSubject('Opportunity Report');
mail.setPlainTextBody('Please see the attached html report');
// Create an email attachment
Messaging.EmailFileAttachment efa =new Messaging.EmailFileAttachment();
efa.setFileName(cont.Id+'report.html');
if (!Test.isRunningTest()){//unable to call .getContent() within tests
b = page.getContent();
}
else{
b = Blob.valueOf('Unit Test Attachment Body');
}
efa.setBody(b);
//attach the PDF /html
efa.setContentType('text/html');
mail.setFileAttachments(newMessaging.EmailFileAttachment[] {efa});
emails.add(mail);
}
Messaging.sendEmail(emails);
When I call this method from a button click it send the attachment and I can see the attachment content is there but when I use batch apex and try to open this the link from eamail it asks user id and password always send me 2k filesize with links to salesforce page.
please let me know if you have comeacross simillar issue
Thanks
K
Instead, render the file as PDF, or turn off the headers so that the JS won't cause the user to be redirected to the login page.
Hi SFDCFox,
Thanks for your response.
The file size even not MB it is 10KB to 100KB. I tried with Renderas PDF and turned off the header and sidebar and did not work.
As I mentioned in my original post it works from button click. when I use the same email attachment thro' batch apex to send email, the VF page is not getting rendered to get the content. I think that is happening.
Can you see any other issue ?
thanks
K
As I stated previously, all mass email attachments are converted, regardless of their size.
is there any way you can suggest to send emails that would not ask user to login and should be without userid/passwords.??
thanks
K
My apologies for the late reply. You must strip the headers from the page before sending it. A salesforce.com page includes logic to automatically redirect to the login page when the session has expired and a page is loaded. I strongly recommend rendering as a PDF for best resuls.
getContent () does not work in batch jobs even in pdf
http://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_pagereference.htm
need to find a different way or suggest something else.
thanks
K