+ Start a Discussion
rupesh ranjanrupesh ranjan 

Why mails are coming into Spam Folder

public pageReference send(){
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  
    List<String> ccAddresses =new List<String>();  
  if (AddRecep != '' && AddRecep != null) {
     ccAddresses  = AddRecep.split(';');
    email.setTargetObjectId(conId);
    email.setCcAddresses(ccAddresses);
    email.setSubject(subject);
    email.setHtmlBody(body);    
  Messaging.SendEmailResult [] res = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {email});  
  for ( Messaging.sendEmailResult result : res ) {
           if ( !res[0].isSuccess () ) {
               System.debug ( result  );
           }          
       }       
 }  
return null;        
}
Amit Chaudhary 8Amit Chaudhary 8
That is not just because of your code. That is because of your email box setting. Click on any email and mark that as non-spam.

OR you can do one thing set the sender email id in you code like below post
1) http://amitsalesforce.blogspot.in/2015/11/default-from-address-while-sending.html


Step 1:-  Setup "Organization-Wide Email Addresses"

1. Navigate Setup -> Email Administration ->  Organization-Wide Email Addresses
2. Click on Add button.
3. Enter email Id and display name of sender.
4. In order to complete this process you need to get verified email id you are putting here

Step 2:- Fetch "Org Wide Email Address" in code like below code.
add below code in your code

for(OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress])
{
  if(owa.DisplayName.contains('System Admin'))
  {
     mail.setOrgWideEmailAddressId(owa.id);
  }
}
 
public pageReference send(){
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  
    List<String> ccAddresses =new List<String>();  
	if (AddRecep != '' && AddRecep != null) 
	{
    ccAddresses  = AddRecep.split(';');
    email.setTargetObjectId(conId);
    email.setCcAddresses(ccAddresses);
    email.setSubject(subject);
    email.setHtmlBody(body);    
	
	for(OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress])
	{
		if(owa.DisplayName.contains('System Admin'))
		{
			email.setOrgWideEmailAddressId(owa.id);
		}
	}

	
  Messaging.SendEmailResult [] res = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {email});  
  for ( Messaging.sendEmailResult result : res ) {
           if ( !res[0].isSuccess () ) {
               System.debug ( result  );
           }          
       }       
 }  
return null;        
}
Let us know if this will help you

 
rupesh ranjanrupesh ranjan
Again mails are coming in Spam folder