sendEmailMessage()
構文
Enterprise SOAP:
1SendEmailResult[] = connection.sendEmailMessage( String[] draftEmailIds);Partner SOAP:
1SendEmailResult[] = connection.sendEmailMessage( ID[] draftEmailIds);使用方法
このコールは、Force.com AppExchange アプリケーション、カスタムアプリケーションなどの、Salesforce 以外のアプリケーションで、最大 10 個のドラフトメールメッセージの送信を行う場合に使用します。メッセージでは標準的なメール属性 (件名行、BCC など) を含めることができ、Salesforce のメールテンプレートを使用することが可能です。平文テキストのほか HTML 形式もサポートされています。HTML メールの状況は、Salesforce を使って追跡できます。送信日、メールが最初に開かれた日、最後に開かれた日、開かれた回数などを確認できます (詳細は、Salesforce オンラインヘルプの「HTML メールの追跡」を参照してください)。
ログインユーザのメールアドレスは、メールヘッダーの [送信元アドレス] 項目に挿入されます。不在の返信も含め、返ってきたメールはすべてログインユーザに送信されます。不達管理が有効で、targetObjectId または targetObjectIds が設定されている場合、不達は Salesforce によって自動的に処理され、該当するレコードが更新されます。それ以外の場合は、ログインユーザに送信されます。
サンプルコード — Java
このサンプルでは、ケースおよびドラフトメールメッセージを作成して、From、To、CC、BCC の各受信者、件名、本文テキストを含むメッセージ項目を設定します。また、添付ファイルを作成し、添付ファイルを含むメールメッセージを送信します。最後に、状況メッセージまたはエラーメッセージがある場合はコンソールに書き込みます。
1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void doSendEmail() {
18 try {
19 //Create a case
20 Case theCase = new Case();
21 theCase.setSubject("Sample Case");
22 SaveResult[] saveResult = connection.create(new SObject[] { theCase });
23 String caseId = saveResult[0].getId();
24
25 //Create a draft EmailMessage
26 EmailMessage message = new EmailMessage();
27 message.setParentId(theCase.getId());
28 message.setBccAddress("bcc@email.com");
29 message.setCcAddress("cc1@salesforce.com; cc2@email.com");
30 message.setSubject("This is how you use the sendEmailMessage method.");
31 message.setFromAddress("from@email.com");
32 message.setFromName("Sample Code");
33 message.setTextBody("This is the text body of the message.");
34 message.setStatus("5"); //"5" means Draft
35 message.setToAddress("to@email.com");
36 saveResult = connection.create(new SObject[] { message });
37 String emailMessageId = saveResult[0].getId();
38
39 //Create an attachment for the draft EmailMessage
40 Attachment att = new Attachment();
41 byte[] fileBody = new byte[1000000];
42 att.setBody(fileBody);
43 att.setName("attachment");
44 att.setParentId(emailMessageId);
45 connection.create(new SObject[] { att });
46
47 //Send the draft EmailMessage
48 SendEmailResult[] results = connection.sendEmailMessage(messages);
49 if (results[0].isSuccess()) {
50 System.out.println("The email was sent successfully.");
51 } else {
52 System.out.println("The email failed to send: " +
53 results[0].getErrors()[0].getMessage());
54 }
55 } catch (ConnectionException ce) {
56 ce.printStackTrace();
57 }引数
なし。