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
mikishiinamikishiina 

How to remove System Administrator's E-mail address form to-address

I have problem.

I am trying to send e-mail using the Apex code with SingleEmailMessage Method.

However, after e-mail transmission, if it is received by a mail client, a system administrator's mail address is added to an address automatically in addition to the specified address.

 

I would like to transmit e-mail only to the specified address,

and  I would like to remove a system administrator's mail address, what should I do?

 

In addition, I need the following.

  • setCcAddresses
  • setBccAddresses
  • setReplyTo
  • setOrgWideEmailAddressId
  • setFileAttachments

 

Therefore,  MassEmailMessage cannot be used.

 

my source code is...

 

public void sendMessage(MailManage__c mmd){
 Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();

 message.setToAddresses(mmd.ToAddress__c);
 message.setCcAddresses(mmd.CCAddress__c);
 message.setBccAddresses(mmd.BCCAddress__c);
 message.setReplyTo(mmd.FromAddress__c);
 message.setOrgWideEmailAddressId(mmd.FromAddressOwe__c);
 User userInfo = [Select u.Id From User u Where u.Profile.Name = 'Administrator'];
 message.setTargetObjectId(userInfo.Id);
 message.setSaveAsActivity(false);
 message.setSubject(mmd.Title__c);
 message.setPlainTextBody(mmd.MainContent__c);

 try{
  System.debug('new Message was sent');
  Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
  System.debug('Message was sent');
 }catch(System.DmlException e){
  System.debug('We caught a DML exception: ' + e.getDmlMessage(0));
 }
}