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
Pairin MasonPairin Mason 

Messaging.sendEmail issue on production

Hi,

I used Messaging.sendEmail(List_of_50emails, false) to send out emails to 50 different email addresses at the single sendEmail call.
And each email sent have bcc to myself to make sure that all of the 50 recipients get their emails.

I test this on sandbox and I recieved  50 bcc emails just fine. But on production, I recieved only 25 bbc emails back.  No matter how many time I tried.

I check the SF Email Logs for a specefic recipient who didn't get the email, and there is no log on that email delivery either. So I assume the system didn't send out emails to some ppl on the emails list at all.

Any advise on where to look would be really helpful. It's pretty emergency to fix this issue. 

Thank you very much. 

 

Amit K AAmit K A
Hi 

Could you please provide the code please which you have written ?

and also let me know the edition of ur org.  
Pairin MasonPairin Mason

Thanks logontokartik and Amit K A.

logontokartik , I had SendEmailResult in place as a Apex debug log, but since it was possible to know which Community user will hit this sendEmail piece, so I cannot use Monitoring > Debug log  to capture this info ealier. So I'm implementing some code to record  SendEmailResult  on every Community user into a Custom object and push it to production and hope it will give me some useful information to fix this issue.

 Amit K A, it's Enterprise edition and this is a code:

 

public static void SendMultiEmails(List<ID> recipients, ID candidate, string orgWideEmailAddress, string templateName, string[] additionalEmails, string title, string body, string creatorName, string dc, string mainNav, string qrId, string commName)
	{
		List<ID> recipients = new List<ID>();
		
		List<GSCForumSubscription__c> uSubscriptions = [Select Id, User__r.Id, ForumCategory__c, CommunityCategory__c  From GSCForumSubscription__c 
															Where ForumCategory__c =: dc.DataCategoryName];
		
		for(GSCForumSubscription__c us : uSubscriptions)
		{
			recipients.add(us.User__r.Id);
		}	
		
		List<string> bccEmails = new List<string>();
   
		List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
		OrgWideEmailAddress owa = [select id, DisplayName, Address from OrgWideEmailAddress where Address = :orgWideEmailAddress limit 1];
		EmailTemplate template = [Select id, body, Name from EmailTemplate where Name = :templateName limit 1];	
		
		for(ID rcp : recipients)
		{
            string recipientName = [SELECT Name FROM User WHERE Id = :rcp].Name;
            
            //rcp isn't printing..... fix later
            string subscriptionEmailBody = 'body';
		  	//Generate the SF mail objects. 
			Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();	
	
			// Who you are sending the email to	
		   	mail.setTargetObjectId(rcp);
		   	
		   	//Where are we emailing from
			mail.setOrgWideEmailAddressId(owa.id);
            
            //What is the title?
            //mail.setSubject('Geocortex Support: New ' + commName + ' - ' + dcProperName + ' Post!');
            mail.setSubject('[Subject - ' + dcProperName + '] Re: ' + title);
			
		   	// The email body to use
			//mail.setTemplateId(template.Id);
			mail.setHTMLbody(subscriptionEmailBody);
            
		  	mail.setUseSignature(false);
		
	   		mail.setBccAddresses(bccEmails);
	   		
		   	//Set Merge Fields and object to attach activity too. If null, attachs to contact.
		   	if (candidate != null)
		   	{	
		   		mail.setWhatId(candidate);	   		
		   	}
		   	
		   	//Saves it as an activity within salesforce.
		   	mail.setSaveAsActivity(false);
		   	
		   	//Add additional emails if necessary
		   	if (additionalEmails != null)
		   	{
		   		mail.setCcAddresses(additionalEmails);
		   	}
			
			//Add the email into a mail package.
			allmsg.add(mail);
		}
		
		List<Messaging.Sendemailresult> result = Messaging.sendEmail(allmsg, false);
		
		// For debugging on SendEmail failure
		if(result[0].isSuccess() == false)
		{
			List<Messaging.Sendemailerror> error = result[0].getErrors();
			system.debug('tt77 - SendEmailInfo: ' + error[0].getFields() + ' / ' + error[0].getTargetObjectId() + ' / ' + error[0].getMessage());
		}
	}
Pairin MasonPairin Mason
Edit:   mail.setBccAddresses(bccEmails);    // bcc to my email address