Salesforce の SingleEmailMessage オブジェクトに "差出人" アドレスを設定したいのですが、これを行う方法がわかりません。ドキュメントには標準の方法が記載されていません。
doNotReply@<somedomain>.com からメールを送信したいのですが、レコードを編集している (これによってメールがトリガされる) 内部ユーザのメールアドレスが差出人アドレスとして設定されます。ユーザに固有でないアドレスを設定したいと考えています。
これを行うには、まず [設定] | [管理] | [メール管理] | [組織のアドレス] メニューに移動して、専用のメールアドレスを設定する必要があります。
組織のアドレスを作成したら (Salesforce では、アドレスを使用する前にその確認を要求されるため、ジャンクアドレスからメールを送信する場合は、確認メールを受信できるように "すべて受信" のメールボックスを設定することをお勧めします)、URL から Id を取得し、Messaging.SingleEmailMessage のインスタンスに対して setOrgWideEmailAddressId(Id) メソッドを使用します。
Id をハードコードしたくない場合は、組織のアドレスを作成した後、次のようにクエリを実行できます。
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'doNotReply@<somedomain>.com'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
if ( owea.size() > 0 ) {
mail.setOrgWideEmailAddressId(owea.get(0).Id);
}000387978

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.