Top > 開発メモ > Mail連携 > 標準Mail

標準Mail

修正 @ Aug 18, 2011 18:07:41

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

送信トレイに入れる

サンプル

  • パラメータ
    • 宛先:mailTo
    • 件名:subject
    • 本文:body
UInt16		cardNo;
LocalID		dbID;
Char		*string;
DmSearchState	state;
MailAddRecordParamsType *cmdPBP;

if (DmGetNextDatabaseByTypeCreator (true, &state,
    sysFileTApplication, 'mail', true, &cardNo, &dbID)
    != dmErrCantFind)
{
 cmdPBP =
 (MailAddRecordParamsType *)MemPtrNew (sizeof(MailAddRecordParamsType));
 if (cmdPBP)
 {
  string = (Char *)MemPtrNew (StrLen (mailTo)
                            + StrLen (subject)
                            + StrLen (body)+ 3); 
  if (string)
  {
   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);
  }
  MemPtrFree (cmdPBP);
 }
}

下書きトレイに入れる

  • 起動コードはsysAppLaunchCmdGoToURL
  • パラメータブロックは文字列。書式は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);
 }
}