BCC stands for "Blind Carbon Copy". Email addresses listed in the BCC field of an email will receive the email, but the BCC list is not transmitted with the email. This is so no one who receives the email can see who was BCC'ed -- that's what is meant by "blind". So, incoming email does not have a BCC field -- only outgoing email can have a BCC field. Therefore, there is NO WAY to obtain BCC information from a received email. You will have to talk to whoever created the requirement and explain that it is not possible.
If you're trying to get BCC address from an email that you have received, I don't think that's possible. The whole idea of the BCC address is that the receiver can't see it.
Messaging.reserveSingleEmailCapacity(2);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {Lead.email};
String[] ccAddresses = new String[] {Lead.email};
// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);
mail.setBccAddresses(lead.bccemail__c) ;
// Specify the address used when the recipients reply to the email.
mail.setReplyTo('sfdcsrini@gmail.com');
// Specify the name used as the display name.
mail.setSenderDisplayName('Salesforce Support');
// Specify the subject line for your email address.
mail.setSubject('New Lead Created : ' + Lead.Id);
// Set to True if you want to BCC yourself on the email.
mail.setBccSender(false);
// Optionally append the salesforce.com email signature to the email.
// The email address of the user executing the Apex Code will be used.
mail.setUseSignature(true);
// Specify the text content of the email.
mail.setPlainTextBody('Your Lead: ' + Lead.Id +' has been created.');
mail.setHtmlBody('Your Lead: ' + Lead.Id +' has been created.'+
'To view your Contact click here.');
// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
global class CreateLeadExample implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Lead lead;
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
Messaging.SingleEmailMessage mail= new Messaing.SingleEmailMessage();
try {
//Look for lead whos name is the email and create it if necessary
List<Lead> leadList = new List<Lead>();
String tempLead = email.FromAddress;
String [] ccAddress=email.ccAddresses;
System.debug('ToAddress'+email.toAddresses);
System.debug('FROMADDRESS = '+email.FromAddress);
System.debug('FROMADDRESS TEMPLEAD = '+tempLead);
String leadQuery = 'select LastName from Lead where LastName = \'' + tempLead +'\'';
leadList = Database.Query(leadQuery);
Integer leadCount = leadList.size();
System.debug('LEAD COUNT FROM THE QUERY -'+leadCount);
if ([select count() from Lead where Name = :email.FromAddress] == 0) {
for (String address : email.ccAddresses)
{
System.Debug('INSIDE IF for LEAD COUNT EQUAL TO 0');
system.debug('EmailAddress'+ email.ccAddresses);
lead = new Lead();
lead.Status = 'New';
lead.LastName = email.FromName;
lead.Company = (email.FromAddress.split('@').get(1));
lead.Email = email.FromAddress;
system.debug(address);
lead.Cc__c=address;
system.debug(lead.Cc__c);
lead.Description='Subject:'+ email.subject + '/n' + email.plainTextBody;
mail.setBccAddresses(lead.Bcc__c);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
insert lead;
//Save any text attachments, if any
if (email.textAttachments != null)
{
for (integer i = 0 ; i < email.textAttachments.size() ; i++) {
Attachment attachment = new Attachment();
// attach to the newly created contact record
attachment.ParentId = lead.Id;
attachment.Name = email.textAttachments[i].filename;
attachment.Body = Blob.valueof(email.textAttachments[i].body);
insert attachment;
}
}
//Save any Binary Attachment
if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
Attachment attachment = new Attachment();
// attach to the newly created contact record
attachment.ParentId = lead.Id;
attachment.Name = email.binaryAttachments[i].filename;
attachment.Body = email.binaryAttachments[i].body;
insert attachment;
}
}
}
else { //Lead already exists
lead = [select Id from Lead where Name = :email.FromAddress];
}
result.success = true;
} catch (Exception e) {
result.success = false;
result.message = 'Error processing email...';
}
return result;
}
}
Here is my sample code.Im able to display cc address in lead.Cc__c field. Can i use singe mail message to populate bcc address .Now its showing Error: Compile Error: Method does not exist or incorrect signature: void setBccAddresses(String) from the type Messaging.SingleEmailMessage at line 46 column 22.Please help me to resolve this? Thanks
global class CreateLeadExample implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Lead lead;
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
Messaging.SingleEmailMessage mail= new Messaing.SingleEmailMessage();
try {
//Look for lead whos name is the email and create it if necessary
List<Lead> leadList = new List<Lead>();
String tempLead = email.FromAddress;
String [] ccAddress=email.ccAddresses;
System.debug('ToAddress'+email.toAddresses);
System.debug('FROMADDRESS = '+email.FromAddress);
System.debug('FROMADDRESS TEMPLEAD = '+tempLead);
String leadQuery = 'select LastName from Lead where LastName = \'' + tempLead +'\'';
leadList = Database.Query(leadQuery);
Integer leadCount = leadList.size();
System.debug('LEAD COUNT FROM THE QUERY -'+leadCount);
if ([select count() from Lead where Name = :email.FromAddress] == 0) {
for (String address : email.ccAddresses)
{
System.Debug('INSIDE IF for LEAD COUNT EQUAL TO 0');
system.debug('EmailAddress'+ email.ccAddresses);
lead = new Lead();
lead.Status = 'New';
lead.LastName = email.FromName;
lead.Company = (email.FromAddress.split('@').get(1));
lead.Email = email.FromAddress;
system.debug(address);
lead.Cc__c=address;
system.debug(lead.Cc__c);
lead.Description='Subject:'+ email.subject + '/n' + email.plainTextBody;
mail.setBccAddresses(new String[]{lead.Bcc__c});
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
insert lead;
//Save any text attachments, if any
if (email.textAttachments != null)
{
for (integer i = 0 ; i < email.textAttachments.size() ; i++) {
Attachment attachment = new Attachment();
// attach to the newly created contact record
attachment.ParentId = lead.Id;
attachment.Name = email.textAttachments[i].filename;
attachment.Body = Blob.valueof(email.textAttachments[i].body);
insert attachment;
}
}
//Save any Binary Attachment
if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
Attachment attachment = new Attachment();
// attach to the newly created contact record
attachment.ParentId = lead.Id;
attachment.Name = email.binaryAttachments[i].filename;
attachment.Body = email.binaryAttachments[i].body;
insert attachment;
}
}
}
else { //Lead already exists
lead = [select Id from Lead where Name = :email.FromAddress];
}
result.success = true;
} catch (Exception e) {
result.success = false;
result.message = 'Error processing email...';
}
return result;
}
}
Now the error is not showing.Lead is not getting created.In debug log Bccaddess is showing null value. System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Email body is required.: [] Thanks
Please add the below send email logic as shown below .. you need to set this values
// First, reserve email capacity for the current Apex transaction to ensure
// that we won't exceed our daily email limits when sending email after
// the current transaction is committed.
Messaging.reserveSingleEmailCapacity(2);
// Processes and actions involved in the Apex transaction occur next,
// which conclude with sending a single email.
// Now create a new single email message object
// that will send out a single email to the addresses in the To, CC & BCC list.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// Strings to hold the email addresses to which you are sending the email.
String[] toAddresses = new String[] {'user@acme.com'};
String[] ccAddresses = new String[] {'smith@gmail.com'};
// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);
// Specify the address used when the recipients reply to the email.
mail.setReplyTo('support@acme.com');
// Specify the name used as the display name.
mail.setSenderDisplayName('Salesforce Support');
// Specify the subject line for your email address.
mail.setSubject('New Case Created : ' + case.Id);
// Set to True if you want to BCC yourself on the email.
mail.setBccSender(false);
// Optionally append the salesforce.com email signature to the email.
// The email address of the user executing the Apex Code will be used.
mail.setUseSignature(false);
// Specify the text content of the email.
mail.setPlainTextBody('Your Case: ' + case.Id +' has been created.');
mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created.<p>'+
'To view your case <a href=https://***yourInstance***.salesforce.com/'+case.Id+'>click here.</a>');
// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
In lead page there are few fields(Description,email id,Bcc ,Cc).These fields should populate values from mail when i create a lead using emailtolead.eg: subject in email should populate in description in lead page.Currently im getting all the values except bcc.I cannot assign the string to bcc .
BCC stands for "Blind Carbon Copy". Email addresses listed in the BCC field of an email will receive the email, but the BCC list is not transmitted with the email. This is so no one who receives the email can see who was BCC'ed -- that's what is meant by "blind". So, incoming email does not have a BCC field -- only outgoing email can have a BCC field. Therefore, there is NO WAY to obtain BCC information from a received email. You will have to talk to whoever created the requirement and explain that it is not possible.
All Answers
Is this what you're looking for?
mail.setBccAddresses(lead.bccemail__c) ;
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm
Thanks to all for your replies.
Here is my sample code.Im able to display cc address in lead.Cc__c field. Can i use singe mail message to populate bcc address .Now its showing Error: Compile Error: Method does not exist or incorrect signature: void setBccAddresses(String) from the type Messaging.SingleEmailMessage at line 46 column 22.Please help me to resolve this?
Thanks
Now the error is not showing.Lead is not getting created.In debug log Bccaddess is showing null value.
System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Email body is required.: []
Thanks
In lead page there are few fields(Description,email id,Bcc ,Cc).These fields should populate values from mail when i create a lead using emailtolead.eg: subject in email should populate in description in lead page.Currently im getting all the values except bcc.I cannot assign the string to bcc .
ChimpConnect, an application will allow you to integrate MailChimp and Salesforce together to optimize your Email Marketing Campaigns.
You can consider these links for more info: https://eshopsync.com/mailchimp-salesforce-integration/
https://eshopsync.com/mailchimp