Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a requirement in which I have to write code to send mail to people who are neither contact nor lead. They are people working in our company and do not have any Salesforce login. I have created a workaround by creating contacts of them. And it is always a dangerous thing to have them in Contact as Admin can delete them by mistake. If not now sometimes in future. So my concern is to have a solution in which I can send mail to them without any fear of loosing there contact as it is a continuous basis process. This mail does not go to our client and wholly and solely for internal purpose. Can somebody help me.

share|improve this question

1 Answer 1

Salesforce provides functionality to send email to any person regardless of Contact or Lead or User. However it is bound with a quite restrictive Salesforce governor limit:

to a maximum of 1,000 external email addresses per day

Here is a sample code to send email to any email address:

    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();                  

    String subject = 'Subject Line ';
    email.setSubject(subject);

    // text
    String body = 'Information you need to send'; 

    // Set HTML body for nice foramtting
    email.setHTMLBody(body);

    // Set eamil address of person who you want to send the email. Also you can set multiple email addresses too.
    email.setToAddresses(new String[]{'name.surname@company.com'});

    Messaging.sendEmail(new Messaging.singleEmailMessage[] {email});
share|improve this answer
    
The problem in the above solution is the hardcoded nature of email address. In my case it can change anytime(due to transfer to another department or etc.). So I have to go back to Sandbox or other means and change it. Scenario: A picklist gets updated on custom object and a mail gets triggered to the internal employee to do a job. Sometime one value gets updated: 2 different mails to 2 different departments. Hopefully you understand my concern. –  Rohit May 13 at 11:51
1  
@rohit To solve this problem you need a custom object and Apex trigger with the solution above. –  regalforce May 13 at 17:18
    
Sorry for late reply. I am doing the same Regal. Thanks. But my problem is that I have to send different mails at different steps so different template. Then how can I send mail after fetching template ID to them. Any solution. –  Rohit May 15 at 5:58
    
Template ID can only be chosen in case of lead/contact. Right? If I am wrong please correct me. –  Rohit May 15 at 6:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.