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

How to send Email to the Contact object email using Apex Email Services?




I want to send the email from to the Email field in contact's object using email services, Is it possible to do this?


I'm able to send emails to users within, i want to send mails to contacts mail in Contacts Object.


Any one please help me how to solve this.




If you just want to send a single message from Apex you can do something like this.


Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); email.setSubject('Subject'); email.setReplyTo('whoever'); email.setSaveAsActivity(false); email.setPlainTextBody('Text body'); String[] toAddresses = new String[] {''}; email.setToAddresses(toAddresses); Messaging.SendEmailResult[] sendResult; //send the eMail sendResult = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });





Thank u very much for replying.........


Is it possible to send to a list of emails in contact object using workflow process... And i want it in automated process.


For example whenever i created a contact it has to send a mail to that contacts email id.


I had checked using workflow but its allowing to send only 5 email addressess

Why not just use a after insert trigger on the contact object?  Or do you have additional rules that need to be applied in workflow?
ok i hav tried tat and all....but i'm not able to send email to contacts email in contacts object, its asking to add any others email's to recieve this notification enter here and its allowing to add 5 emails only

I think you mean you have tried creating a Workflow Rule on Contacts (this has a 5 emails only limit), knichols was suggesting to use an Apex Trigger which doesn't have this limit.


It looks like Salesforce have updated Workflow Rule Email Alerts - it seems you can assign an Email Field (Use the Search picklist when creating an Email Alert and set to Email Field) as a Recipient.  You could use that to see if that does what you want.