Sending Email from Guest User Profile- Email No Receiving Email
Send email using guest user
public pageReference generatePDF() {
if(caseId != '') {
Case cs = [select Id,CaseNumber,Quote_Number__c from Case where Id=:caseId LIMIT 1];
pageReference pdfPage = Page.EnceliumForm;
blob pdfBody;
if(Test.isRunningTest()) {
pdfBody = blob.valueOf('Unit.Test');
} else {
pdfBody = pdfPage.getContentAsPdf();
}
system.debug('in method--------->>'+caseId+cs);
system.debug('pdfFile===>'+pdfBody);
attachment pdfFile = new attachment();
pdfFile.isPrivate = false;
pdfFile.body = pdfBody;
pdfFile.parentId = cs.Id; // '5003B000005oRIx';
pdfFile.Name = 'Encelium Request form.pdf';
insert pdfFile;
system.debug('## pdfFile===>'+pdfFile);
if(string.isNotBlank(ecContactEmail)) {
system.debug('## ecContactEmail===>'+ecContactEmail);
OrgWideEmailAddress owea = new OrgWideEmailAddress();
owea = [SELECT Id, Address, DisplayName FROM
OrgWideEmailAddress WHERE displayname='Legrand CRM Support Team' limit 1];
string conEmail = ecContactEmail;
Messaging.EmailFileAttachment att = new Messaging.EmailFileAttachment();
att.setBody(pdfBody);
att.setContentType('application/pdf');
att.setFileName('attachment.pdf');
Messaging.SingleEmailMessage mess = new Messaging.SingleEmailMessage();
mess.setSubject('Encelium Request Form:'+' Your Case Number: '+ cs.CaseNumber);
mess.setToAddresses(new String[]{conEmail});
mess.setHtmlBody('Please find attached self-signed Encelium Request Form. <br/><br/> Please do not reply to this mail');
mess.setFileAttachments(new Messaging.EmailFileAttachment[]{att});
mess.setSaveAsActivity(false);
mess.setOrgWideEmailAddressId(owea.id);
//Messaging.sendEmail(new Messaging.Email[]{mess});
system.debug('## End===>');
try{
List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.Email[]{mess});
if(results[0].success){
system.debug('## success===>');
}else{
system.debug('## Fail===>');
}
} catch(Exception ex){
system.debug('## Exception===>'+ex.getMessage() +' LN ='+ex.getLineNumber());
}
}
}
return new pagereference('http://www.Legrand.us').setRedirect(true);
}