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
Ty WhitfieldTy Whitfield 

Set the emailmessage fromaddress via API

I have successfully been able to add an emailMessage to SF via the API.  I will need to do one of the two options:
  1. Not have SF send the email to the recipient once added.  This is because we have already sent the email and just placing a copy in SF for our records
  2. Have the ability to change the fromAddress via the API.  If we remove the email sent from our website and only have the SF one to be sent, we will need to change the from email address.  I have added the email to the Organization-Wide Email addresses and associated it to the correct profile, however, I don't know where to switch it.
 
SingleEmailMessage emailMessage = new SingleEmailMessage();
            if (!string.IsNullOrEmpty(templateid))
            {
                emailMessage.templateId = templateid;
            }
            else
            {
                emailMessage.subject = subject;
                emailMessage.htmlBody = Server.UrlDecode(body) ;
            }

            emailMessage.toAddresses = new String[] { email };
            emailMessage.saveAsActivity = true;
            emailMessage.targetObjectId = contactId;

            SingleEmailMessage[] messages = { emailMessage };
            SendEmailResult[] results = binding.sendEmail(messages);

            if (results[0].success)
            {
                // Console.WriteLine("The email was sent successfully.");
            }
            else
            {
                SendEmail("xxxxxx@xxx.com", "Error SingleEmailMessage add", "The email failed to send: " + results[0].errors[0].message);

            }


            sflogout();

 
Abdul KhatriAbdul Khatri
I am not sure if I am able to understand you issue here. 

Can you please provide the complete implementation of the email message code? Is it in any apex class?
Ty WhitfieldTy Whitfield
No, this is C# code being implement from our website.   What we are doing is sending an email to the user from the website.  We just want to put a copy of the email in SF for history purposes and if the user says that didn't receive it, it will allow for the admin to easily resend to the user.  The problem is with the code above, it places it in Salesforce but sends the email out again.  So, we have two options, either figure out a way so that Salesforce doesn't send the email or stop the one from the website and just place in Salesforce and allow for it to send to the customer.  The issue with the latter is that the from email address tied to the account processing needs to be changed to noreply.  I don't know how to do that.
Abdul KhatriAbdul Khatri
Currently what mechanism you have build within Salesforce to resent the email in case if the user complains of not receiving one?
Ty WhitfieldTy Whitfield
That function is manual, not via Salesforce but that doesn't affect my question