• 追加された行はこの色です。
  • 削除された行はこの色です。
&tag(Palm,Program);

Palm標準のMailを使って、他のアプリからメールを送る方法。

-起動コードは''[[sysAppLaunchCmdGoToURL:http://www.palmos.com/dev/support/docs/palmos/AppLaunchCodes.html#1012191]]''。
-パラメータはHTML形式で、宛先、件名、本文をそれぞれmailto:、subject:、body:の後に書く。
-メール編集画面が開く。
-Versa Mail、CLIE Mailも同じ方法で良さそう。
#contents

*送信トレイに入れる [#ieb53e7e]

-起動コード:[[sysAppLaunchCmdAddRecord:http://www.palmos.com/dev/support/docs/palmos/AppLaunchCodes.html#1011469]]。
-パラメータブロック:[[MailAddRecordParamsType:http://www.palmos.com/dev/support/docs/palmos/AppLaunchCodes.html#1011483]]

サンプル
-パラメータ
--宛先:mailTo
--件名:subject
--本文:body

 UInt16		cardNo;
 LocalID		dbID;
 DmSearchStateType searchInfo;
 Char		*cmdPBP;
 Char		*string;
 DmSearchState	state;
 MailAddRecordParamsType *cmdPBP;
 
 if (DmGetNextDatabaseByTypeCreator(true, &searchInfo,
 if (DmGetNextDatabaseByTypeCreator (true, &state,
     sysFileTApplication, 'mail', true, &cardNo, &dbID)
     != dmErrCantFind)
 {
  cmdPBP = (Char *)MemPtrNew (
             StrLen (MyEmailAddressStr)
           + StrLen (MyEmailSubjectStr)
           + StrLen (MyEmailBodyStr)
           + 23);
 
  StrCopy (cmdPBP, "mailto:");
  StrCat (cmdPBP, MyEmailAddressStr);
  if (*subject || *body)
  cmdPBP =
  (MailAddRecordParamsType *)MemPtrNew (sizeof(MailAddRecordParamsType));
  if (cmdPBP)
  {
   StrCat (cmdPBP, "?");
   if (*subject)
   string = (Char *)MemPtrNew (StrLen (mailTo)
                             + StrLen (subject)
                             + StrLen (body)+ 3); 
   if (string)
   {
    StrCat (cmdPBP, "subject=");
    StrCat (cmdPBP, MyEmailSubjectStr);
    StrPrintF (string, "%s%c%s%c%s%c",
               mailTo, chrNull, subject, chrNull, body, chrNull);
 
    cmdPBP->secret = false;
    cmdPBP->signature = true;
    cmdPBP->confirmRead = false;
    cmdPBP->confirmDelivery = false;
    cmdPBP->priority = mailPriorityNormal;
    cmdPBP->padding = 0;
    cmdPBP->subject = string + StrLen (mailTo) + 1;
    cmdPBP->from = "";
    cmdPBP->to = string;
    cmdPBP->cc = "";
    cmdPBP->bcc = "";
    cmdPBP->replyTo = "";
    cmdPBP->body = string + StrLen (mailTo) + StrLen (subject) + 2;
 
    if (MemPtrSetOwner (cmdPBP, 0) == errNone
     && MemPtrSetOwner (string, 0) == errNone)
     SysAppLaunch (cardNo, dbID, 0,
                   sysAppLaunchCmdAddRecord, cmdPBP, &result);
    MemPtrFree (string);
   }
   if (*body)
   {
    if (*subject)
     StrCat (cmdPBP, "&");
    StrCat (cmdPBP, "body=");
    StrCat (cmdPBP, MyEmailBodyStr);
   }
   MemPtrFree (cmdPBP);
  }
 
  if (MemPtrSetOwner(cmdPBP, 0) == errNone)
   SysUIAppSwitch (cardNo, dbID, sysAppLaunchCmdGoToURL, cmdPBP);
  else
   MemPtrFree (cmdPBP);
 }

*下書きトレイに入れる [#mf81b6fa]

別の方法
-起動コード:''[[sysAppLaunchCmdAddRecord:http://www.palmos.com/dev/support/docs/palmos/AppLaunchCodes.html#1011469]]''。
-パラメータブロック:''[[MailAddRecordParamsType:http://www.palmos.com/dev/support/docs/palmos/AppLaunchCodes.html#1011483]]''
-起動コードは[[sysAppLaunchCmdGoToURL:http://www.palmos.com/dev/support/docs/palmos/AppLaunchCodes.html#1012191]]。
-パラメータブロックは文字列。書式はHTML形式。~
本来は、
 mailto:aaa@bbb.com?subject=件名&body=本文
だが、これだとmailto以外のパラメータが入ったときに上手くいかないので、
 mailto:?=&to=aaa@bbb.com &subject=件名 &body=本文
とした方が良さそう(?)

で、編集画面を開かずに全ての情報を渡す方法も有る。
サンプル
 UInt16		cardNo;
 LocalID		dbID;
 DmSearchStateType state;
 UInt32		result;
 Char		*cmdPBP;
 Char		gotoURLString[] = "mailto:?=&to=%s &subject=%s &body=%s "
 
 if (DmGetNextDatabaseByTypeCreator(true, &state,
     sysFileTApplication, 'mail', true, &cardNo, &dbID)
     != dmErrCantFind)
 {
  cmdPBP = (Char *)MemPtrNew (StrLen (gotoURLString)
                            + StrLen (mailTo)
                            + StrLen (subject)
                            + StrLen (body) + 1);
  if (cmdPBP)
  {
   StrPrintF (cmdPBP, gotoURLString, mailTo, subject, body);
   if (MemPtrSetOwner(cmdPBP, 0) == errNone)
    SysAppLaunch (cardNo, dbID, 0, sysAppLaunchCmdGoToURL, cmdPBP, &result);
   MemPtrFree (cmdPBP);
  }
 }