You need to sign in to do that
Don't have an account?

Using fromAddress while sending mail through salesforce
Hi All
We have integrated salesforce using SOAP in C#. We are trying to send mail using salesforce templates through the code. But we are unable to provide fromAddress in the mail. Below is the code for the same :
SingleEmailMessage message = new SingleEmailMessage();
message.emailPriority = EmailPriority.High;
message.saveAsActivity = false;
message.useSignature = true;
message.templateId = templateId;
message.targetObjectId = CrmId;
SingleEmailMessage[] messages = { message };
SendEmailResult[] results = _sf.sendEmail(messages);
Please let us know a way to add fromAddress while sending mail as we are unable to find any option for that.
Regards
Ankit
We have integrated salesforce using SOAP in C#. We are trying to send mail using salesforce templates through the code. But we are unable to provide fromAddress in the mail. Below is the code for the same :
SingleEmailMessage message = new SingleEmailMessage();
message.emailPriority = EmailPriority.High;
message.saveAsActivity = false;
message.useSignature = true;
message.templateId = templateId;
message.targetObjectId = CrmId;
SingleEmailMessage[] messages = { message };
SendEmailResult[] results = _sf.sendEmail(messages);
Please let us know a way to add fromAddress while sending mail as we are unable to find any option for that.
Regards
Ankit
You have to configure the Organization-Wide Email address first. For that Please go to Email admistration and create a create a org wide email address. You can pass in the ID to an OrgWideEmailAddress record when calling sendEmail() for a SingleEmailMessage. For the reciever it will show this id as the sender id.
go through this link
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_orgwideemailaddress.htm
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
EmailTemplate et=[Select id,name,HtmlValue,Subject,body from EmailTemplate where DeveloperName = 'STILL_WAITING_FOR_REPLY_TO_Q_EMAIL'];
String str =et.HtmlValue;
mail.sethtmlBody(str);
mail.setToAddresses(sendTo);
mail.setSaveAsActivity(false);
Messaging.SendEmailresult [] emResult = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
The organization-wide email address will help if I have to send mails from one salesforce account. But here my case many clients are using our wepapp through salesforce and we need to go and tell each client to do so. We need to get it done through code so that it can handle all clients.Please suggest.
@Head In Cloud
We need to provide fromAddress while sending mail. We are able to get toAddress and EmailTemplate
Insufficiant information. But I' ll try to answer with the little info have.
Create an Organization-Wide Addresses
Setup -> Administration Setup -> Email Administration -> Organization-Wide Addresses menu (Salesforce will require you to confirm the address prior to using it,)
Then ,
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'doNotReply@blahblah.com']; Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); if ( owea.size() > 0 ) { message.setOrgWideEmailAddressId(owea.get(0).Id); }
Yes, we have already tested it and by default fromAddress is set to id of user who is sending the mail But here we want a provision to set fromAddress to the id of some other user of same company