+ Start a Discussion
Mark Lewis 21Mark Lewis 21 

Using a noreply.***** email address when autoresponse trigger is activated

I have an autoresponse email trigger with this code
trigger EmailToLeadResponseTrigger on Lead (after insert) {
    //Query on template object
    EmailTemplate emailTemplate = [SELECT id FROM EmailTemplate WHERE name = :'Sales: Lead Created'];
    //List of emails
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    
    for (Lead lead : [SELECT Id, Lead.Email FROM Lead WHERE Id IN : Trigger.new]) {
        if (lead.Email != null) {
            //Initialize messaging method
            Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();
            //Set object Id
            singleMail.setTargetObjectId(lead.Id);
            //Set template Id
            singleMail.setTemplateId(emailTemplate.Id);
            //Flag to false to stop inserting activity history
            singleMail.setSaveAsActivity(false);
            //Add mail
            emails.add(singleMail);
        }
    }
    //Send mail
    Messaging.sendEmail(emails);	    
}

However, in my inbox it actually shows the user im using's email adress. Can I make this hidden or one of those "noreply@....com" emails where It just rejects replies to that given email?
Best Answer chosen by Mark Lewis 21
badibadi
add These two lines before emails.add(singleMail);

singleMail.setReplyTo('donotreply@do-not-reply.com');
singleMail.setSenderDisplayName('Automated Message - Do not Reply');

All Answers

badibadi
add These two lines before emails.add(singleMail);

singleMail.setReplyTo('donotreply@do-not-reply.com');
singleMail.setSenderDisplayName('Automated Message - Do not Reply');
This was selected as the best answer
Mark Lewis 21Mark Lewis 21
Hey guys thanks for the reply. I believe that will suffice. Dont think you can go further than that from now