`
guowee
  • 浏览: 177280 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

mobile receive SMS by setting Notification

阅读更多

1. Fisrt Set the Following Class that process Notification
and you can re-write Function Code

ULONG MAPIAdviseSink::OnNotify(ULONG cNotif, LPNOTIFICATION lpNotifications)

run this Process when a new Message(Mail or SMS) or others operation flag you set.

class MAPIAdviseSink : public IMAPIAdviseSink
{
public:
MAPIAdviseSink();
virtual ULONG OnNotify(ULONG cNotif, LPNOTIFICATION lpNotifications);
virtual ULONG AddRef() { return ++refs; }
virtual HRESULT QueryInterface( REFIID iid, void ** ppvObject) { return E_NOTIMPL; }
virtual ULONG Release();
HRESULT prevResult;
private:
ULONG refs;
};

MAPIAdviseSink *pAdviseSink;

MAPIAdviseSink::MAPIAdviseSink(): refs(0)
{
}

ULONG MAPIAdviseSink::OnNotify(ULONG cNotif, LPNOTIFICATION lpNotifications)
{
//ToDO: rewrite here...
AfxMessageBox(TEXT("new message in"));
/*********************************/
HRESULT hr;
ICEMAPISession * pSession = NULL;

hr = MAPIInitialize(NULL);
hr = MAPILogonEx(0, NULL, NULL, 0, (LPMAPISESSION *)&pSession);

/*****************************/
static const SizedSPropTagArray (2, spta) = { 2, PR_DISPLAY_NAME, PR_ENTRYID };

SRowSet *prowset = NULL;
CComPtr ptbl;
CComPtr pStore;

// Get the table of accounts
hr = pSession->GetMsgStoresTable(0, &ptbl);

// set the columns of the table we will query
hr = ptbl->SetColumns((SPropTagArray *) &spta, 0);

while (TRUE)
{
// Free the previous row
FreeProws (prowset);
prowset = NULL;

hr = ptbl->QueryRows (1, 0, &prowset);
if ((hr != S_OK) || (prowset == NULL) || (prowset->cRows == 0))
return -1;

ASSERT (prowset->aRow[0].cValues == spta.cValues);
SPropValue *pval = prowset->aRow[0].lpProps;

ASSERT (pval[0].ulPropTag == PR_DISPLAY_NAME);
ASSERT (pval[1].ulPropTag == PR_ENTRYID);

if (!_tcscmp(pval[0].Value.lpszW, TEXT("SMS")))
{
// Get the Message Store pointer
hr = pSession->OpenMsgStore(0, pval[1].Value.bin.cb, (LPENTRYID)pval[1].Value.bin.lpb, 0, 0, &pStore);

/**********************/
static const SizedSSortOrderSet(1, sortOrderSet) = { 1, 0, 0, { PR_MESSAGE_DELIVERY_TIME, TABLE_SORT_DESCEND } };
static const SizedSPropTagArray (3, spta) = { 3, PR_SENDER_NAME, PR_SUBJECT, PR_MESSAGE_DELIVERY_TIME };
HRESULT hr = S_OK;
LPENTRYID pEntryId = NULL;
ULONG cbEntryId = 0;
CComPtr pFolder;
CComPtr ptbl;
ULONG ulObjType = 0;
SRowSet *prowset = NULL;

// Get the inbox folder
hr = pStore->GetReceiveFolder(NULL, MAPI_UNICODE, &cbEntryId, &pEntryId, NULL);

// 2 we have the entryid of the inbox folder, let's get the folder and messages in it
hr = pStore->OpenEntry(cbEntryId, pEntryId, NULL, 0, &ulObjType, (LPUNKNOWN*)&pFolder);

// 3 From the IMAPIFolder pointer, obtain the table to the contents
hr = pFolder->GetContentsTable(0, &ptbl);

// 4 Sort the table that we obtained. This is determined by the sortOrderSet variable
hr = ptbl->SortTable((SSortOrderSet *)&sortOrderSet, 0);

// 5 Set the columns of the table we will query. The columns of each row are determined by spta
hr = ptbl->SetColumns ((SPropTagArray *) &spta, 0);

// now get first message in the table
// Free the previous row
FreeProws (prowset);
prowset = NULL;

hr = ptbl->QueryRows (1, 0, &prowset);
if ((hr != S_OK) || (prowset == NULL) || (prowset->cRows == 0))
return -1;

ASSERT (prowset->aRow[0].cValues == spta.cValues);
SPropValue *pval = prowset->aRow[0].lpProps;

// 6 Get the three properties we need: Sender name, Subject, and Delvery time.
ASSERT (pval[0].ulPropTag == PR_SENDER_NAME);
ASSERT (pval[1].ulPropTag == PR_SUBJECT);
ASSERT (pval[2].ulPropTag == PR_MESSAGE_DELIVERY_TIME);

LPCTSTR pszSender = pval[0].Value.lpszW;
LPCTSTR pszSubject = pval[1].Value.lpszW;
SYSTEMTIME st = {0};
FileTimeToSystemTime(&pval[2].Value.ft, &st);

// 7 Pass the parameters to a function to archive (this function is not written)
//hr = AppendToFile(pszFilename, pszSender, pszSubject, st);
AfxMessageBox(pszSubject);

/**********************/
}
}
/*****************************/

hr = pSession->Logoff(0, 0, 0);

pSession->Release();
pSession = NULL;
MAPIUninitialize();
/*********************************/

AfxMessageBox(lpNotifications->info.newmail.lpszMessageClass);
return 0;
}

ULONG MAPIAdviseSink::Release()
{
return 0;
}

 

2. the code following put on your main Program to set
what kinds of Notification that you want to Process.

you can modify operation flag at
hr = pStore->Advise(0, NULL, fnevObjectCreated | fnevNewMail | fnevObjectMoved | fnevObjectDeleted,pAdviseSink, &m_ulAdviseConnection);
for Example: the upper code we set opFlags when SMS Created, NewMail, Moved, Deleted
it will call
MAPIAdviseSink::OnNotify to Process this new Message.
it is an Event-Driven Method.

HRESULT SaveMessages(IMsgStore *pStore, LPCTSTR pszFilename);
//HRESULT SaveSmsMessages(IMAPISession *pSession, LPCTSTR pszFilename);

HRESULT SaveSmsMessages(IMAPISession *pSession, LPCTSTR pszFilename)
{
static const SizedSPropTagArray (2, spta) = { 2, PR_DISPLAY_NAME, PR_ENTRYID };

HRESULT hr;
SRowSet *prowset = NULL;
CComPtr ptbl;
CComPtr pStore;

//---------------------
//IMAPIAdviseSink *pAdviseSink = NULL;
//ULONG m_ulAdviseConnection;

////HrThisThreadAdviseSink(new MyMsgStoreAdviseSink(),&msgStoreAdviseSink);

//hr = pSession->Advise(0, NULL, fnevNewMail | fnevObjectMoved , (LPMAPIADVISESINK)pAdviseSink, &m_ulAdviseConnection);
//
//if(hr == S_OK)
//{
// LPNOTIFICATION lpNotifications = NULL;
// ULONG res = pAdviseSink->OnNotify(0, lpNotifications);
// if(res != 0)
// AfxMessageBox(L"pAdviseSink->OnNotify FAIL");
// AfxMessageBox(L"pass");

// pAdviseSink->Release();
//}else{
// AfxMessageBox(L"pSession->Advise Fail");
//}




//---------------------

// Get the table of accounts
hr = pSession->GetMsgStoresTable(0, &ptbl);
//CHR(hr);

// set the columns of the table we will query
hr = ptbl->SetColumns((SPropTagArray *) &spta, 0);
//CHR(hr);

while (TRUE)
{
// Free the previous row
FreeProws (prowset);
prowset = NULL;

hr = ptbl->QueryRows (1, 0, &prowset);
if ((hr != S_OK) || (prowset == NULL) || (prowset->cRows == 0))
break;

ASSERT (prowset->aRow[0].cValues == spta.cValues);
SPropValue *pval = prowset->aRow[0].lpProps;

ASSERT (pval[0].ulPropTag == PR_DISPLAY_NAME);
ASSERT (pval[1].ulPropTag == PR_ENTRYID);

if (!_tcscmp(pval[0].Value.lpszW, TEXT("SMS")))
{
// Get the Message Store pointer
hr = pSession->OpenMsgStore(0, pval[1].Value.bin.cb, (LPENTRYID)pval[1].Value.bin.lpb, 0, 0, &pStore);
//CHR(hr);

//*************************************************
pAdviseSink = new MAPIAdviseSink();
ULONG m_ulAdviseConnection=0;

hr = pStore->Advise(0, NULL, fnevObjectCreated | fnevNewMail | fnevObjectMoved | fnevObjectDeleted,pAdviseSink, &m_ulAdviseConnection);
if(hr == S_OK)
{
}else{
AfxMessageBox(L"pSession->Advise Fail");
}
//*************************************************

//SaveMessages(pStore, pszFilename);
}
}

Error:
FreeProws (prowset);
return hr;
}
/*
HRESULT SaveMessages(IMsgStore *pStore, LPCTSTR pszFilename)
{
static const SizedSSortOrderSet(1, sortOrderSet) = { 1, 0, 0, { PR_MESSAGE_DELIVERY_TIME, TABLE_SORT_DESCEND } };
static const SizedSPropTagArray (3, spta) = { 3, PR_SENDER_NAME, PR_SUBJECT, PR_MESSAGE_DELIVERY_TIME };
HRESULT hr = S_OK;
LPENTRYID pEntryId = NULL;
ULONG cbEntryId = 0;
CComPtr pFolder;
CComPtr ptbl;
ULONG ulObjType = 0;
SRowSet *prowset = NULL;

// 1 First retrieve the ENTRYID of the Inbox folder of the message store
// Get the inbox folder
hr = pStore->GetReceiveFolder(NULL, MAPI_UNICODE, &cbEntryId, &pEntryId, NULL);
//CHR(hr);

// 2 we have the entryid of the inbox folder, let's get the folder and messages in it
hr = pStore->OpenEntry(cbEntryId, pEntryId, NULL, 0, &ulObjType, (LPUNKNOWN*)&pFolder);
//CHR(hr);
ASSERT(ulObjType == MAPI_FOLDER);

// 3 From the IMAPIFolder pointer, obtain the table to the contents
hr = pFolder->GetContentsTable(0, &ptbl);
//CHR(hr);

// 4 Sort the table that we obtained. This is determined by the sortOrderSet variable
hr = ptbl->SortTable((SSortOrderSet *)&sortOrderSet, 0);
//CHR(hr);

// 5 Set the columns of the table we will query. The columns of each row are determined by spta
hr = ptbl->SetColumns ((SPropTagArray *) &spta, 0);
//CHR(hr);

// now iterate through each message in the table
while (TRUE)
{
// Free the previous row
FreeProws (prowset);
prowset = NULL;

hr = ptbl->QueryRows (1, 0, &prowset);
if ((hr != S_OK) || (prowset == NULL) || (prowset->cRows == 0))
break;

ASSERT (prowset->aRow[0].cValues == spta.cValues);
SPropValue *pval = prowset->aRow[0].lpProps;

// 6 Get the three properties we need: Sender name, Subject, and Delvery time.
ASSERT (pval[0].ulPropTag == PR_SENDER_NAME);
ASSERT (pval[1].ulPropTag == PR_SUBJECT);
ASSERT (pval[2].ulPropTag == PR_MESSAGE_DELIVERY_TIME);

LPCTSTR pszSender = pval[0].Value.lpszW;
LPCTSTR pszSubject = pval[1].Value.lpszW;
SYSTEMTIME st = {0};
FileTimeToSystemTime(&pval[2].Value.ft, &st);

// 7 Pass the parameters to a function to archive (this function is not written)
//hr = AppendToFile(pszFilename, pszSender, pszSubject, st);
//AfxMessageBox(pszFilename);
//AfxMessageBox(pszSender);
AfxMessageBox(pszSubject);
//CHR(hr);
}

Error:
FreeProws (prowset);
MAPIFreeBuffer(pEntryId);
return hr;
}
*/

void CSYDlg::OnBnClickedButton1()
{
HRESULT hr;
ICEMAPISession * pSession = NULL;

hr = MAPIInitialize(NULL);
hr = MAPILogonEx(0, NULL, NULL, 0, (LPMAPISESSION *)&pSession);

SaveSmsMessages(pSession, L"TestFileName");

hr = pSession->Logoff(0, 0, 0);

pSession->Release();
pSession = NULL;
}

if you want to know Read SMS can ref:
mobile read sms 透過MAPI
it tell WHY you can not use SMSOPEN(...) to get incoming Message

分享到:
评论

相关推荐

    Laravel开发-sms-notification

    "Laravel开发-sms-notification"主题涵盖的内容主要是如何在Laravel项目中集成和使用短信通知服务。 首先,Laravel的通知系统是基于事件驱动的,它允许开发者通过简单的接口发送多种类型的通知,包括邮件、短信、推...

    Laravel开发-laravel-mobile-notification

    本文将深入探讨“Laravel开发-laravel-mobile-notification”这一主题,特别是如何利用Laravel/Lumen发送推送通知到移动设备,包括Apple Push Notification (APN) 和 Google Cloud Messaging (GCM)。 首先,Laravel...

    Laravel开发-dhiraagu-sms-notification

    在本文中,我们将深入探讨如何在 Laravel 框架中使用 Dhiraagu SMS 网关来实现批量发送短信的功能。Laravel 是一个流行的开源 PHP 框架,以其优雅的语法和强大的功能深受开发者喜爱。Dhiraagu 是马尔代夫的一家电信...

    C# 高级版Notification for windows mobile(WM)

    首先,了解`Notification`的概念。通知通常分为几种类型,例如弹窗通知、声音提示、震动反馈等,这些都用于吸引用户的注意力。在Windows Mobile中,我们可以利用API和C#的强大力量,定制适合不同场景的通知样式。 1...

    Laravel开发-laravel-notification-channel-turbosms

    而 `laravel-notification-channel-turbosms` 是 Laravel 的一个通知频道,专门用于集成 TurboSMS 服务,允许开发者通过 SMS 来发送通知。 首先,理解 `laravel-notification-channel-turbosms` 的工作原理至关重要...

    Notification

    在Android开发中,`Notification`是用户界面的一个关键组件,用于在状态栏向用户显示重要的信息或提醒。在"疯狂Android中有关Notification的简单例子"这个主题中,我们将深入探讨`Notification`的基本概念、创建过程...

    Ajax-SMS-based-Notification-system.zip

    Ajax-SMS-based-Notification-system.zip,通知系统是一个项目,它将帮助教师通知学生任何重要的信息,如时间表的变化,任何即将举行的研讨会和其他信息。此信息将通过短信共享,ajax代表异步javascript和xml。它是...

    Play midi files and receive notification callbacks to easily

    Play midi files and receive notification callbacks to easily implement repeating music. No special controls needed it’s done through API!

    Notification最新用法、实现Notification的通知栏常驻、Notification的big View、解决Notification点击无效

    在Android开发中,Notification是应用与用户交互的重要方式,它能够在状态栏显示消息,即使用户不在应用程序中也能接收到信息。本教程将深入探讨Notification的最新用法,如何实现通知栏常驻,以及如何利用big View...

    Laravel开发-laravel-notification-channel-voicecombg

    在本文中,我们将深入探讨如何在 Laravel 开发中利用 `laravel-notification-channel-voicecombg` 扩展包实现 VoiceCom BG 通知频道。Laravel 是一个流行的 PHP 框架,它为开发者提供了优雅的方式来构建 web 应用...

    Notification示例

    本示例着重讲解了如何创建和使用不同类型的Notification,包括普通Notification、折叠式Notification以及悬挂式Notification,并涉及到Notification的显示等级设置。 1. **普通Notification**: 这是最基础的...

    Notification的示例源码

    在Android开发中,`Notification`是用户界面的一个关键组件,用于在状态栏中显示消息,即使应用程序在后台运行,也能提醒用户有新的活动或事件发生。`Notification`的设计旨在提供一致且非侵入性的用户体验,使得...

    android notification完全解析Demo

    在Android开发中,Notification是应用与用户交互的重要方式,它能够在状态栏中显示信息,即使用户不在应用程序中也能提醒用户有新的活动或消息。本文将深入解析Android Notification的工作原理、设计模式以及如何...

    Android NOtification 使用

    在Android系统中,Notification是应用与用户交互的重要方式,它能提醒用户有新的事件或信息需要处理,即使应用不在前台运行。Notification分为多种类型,包括Toast、StatusBar Notification和Dialog Notification,...

    Notification顶部通知栏demo

    在Android开发中,`Notification`是系统提供的一种机制,它能够在状态栏或者顶部通知栏显示信息,即使应用在后台运行或者被用户关闭,仍然能够向用户传达关键信息。本示例"Notification顶部通知栏demo"显然是为了...

    Notification Demo

    在Android开发中,Notification是应用与用户交互的重要方式之一,特别是在后台运行时,它能向用户提供关键信息,而不会打扰到他们的主要活动。"Notification Demo"是一个示例项目,专门展示了如何在Android应用中...

    Ext JS Notification 插件

    在Ext JS中,“Notification”插件是用于显示通知消息的一个组件,它可以帮助开发者在用户界面上创建吸引人且易于理解的提示信息。本文将深入探讨Ext JS Notification插件的使用方法、功能特性以及如何集成到项目中...

    实现Notification的通知栏常驻

    在Android系统中,Notification是应用与用户交互的重要方式之一,特别是在后台运行时,它能向用户提供关键信息。常驻Notification是指即使用户关闭了应用程序,Notification仍然保留在通知栏,持续提醒用户有未处理...

Global site tag (gtag.js) - Google Analytics