You Are Here:

Community: Blogs

Paul Todd's Forum Nokia Blog

Sending emails using RSendAsMessage

Paul.Todd | 14 March, 2007 23:55

What a manic month.... Due to work overload postings have been on thin ground so here's a nice technical one!

This week on the forums I notices someone asking how  to use RSendAsMessage to send an email. How hard could it possibly be, sending a message via bluetooth or SMS is trivial...

The problem is email is supported by a number of different MTM's so there is not one hardcoded UID for an email MTM.

This bit of code is going to show the "hacky" way to get the email uids and names from which you could allow the
user to select or just take the first one presented. Next posting we will rewrite it to it the proper way, but first we need to do it the simple way as this fairly complex by itself.


// Setup the bits we need...

// This holds the text for the account
    CDesCArray* emailAccountNames = new (ELeave) CDesCArrayFlat(4);
    CleanupStack::PushL(emailAccountNames);
// This holds the account ids for the accounts name
// each account name is matched directly to an account id
    RArray<TSendAsAccount> emailAccountIds;
    CleanupClosePushL(emailAccountIds);

// The send as session
    RSendAs sa;
    User::LeaveIfError(sa.Connect());
    CleanupClosePushL(sa);

// The message types in the send as session
    CSendAsMessageTypes* saMessageTypes = CSendAsMessageTypes::NewL();
    CleanupStack::PushL(saMessageTypes);

// The accounts in the send as session
    CSendAsAccounts* saAccounts = CSendAsAccounts::NewL();
    CleanupStack::PushL(saAccounts);

// First we filter to get only those mtm that can send a message
    sa.FilterAgainstCapability(KUidMtmQueryCanSendMsg);
    sa.FilteredMessageTypesL(*saMessageTypes);

// Now for each message type that can send
// a message we check to see if it is called
// E-mail and if so we will check the accounts
// to make sure there is at least one account.
// For example we would get an SMTP message type
// as that can send a message but it would potentially
// have no accounts so just ignore it
    TInt current =0;
    while( current < saMessageTypes->Count())
        {
        // Get a list of all the accounts for the current message type
        sa.AvailableAccountsL(saMessageTypes->MessageTypeUid(current), *saAccounts);

        // now see if its name is "E-mail" and it has at least one account
        if (saMessageTypes->NameFromUidL(saMessageTypes->MessageTypeUid(current)) != KEmail || saAccounts->Count() == 0)
            saMessageTypes->RemoveMessageType(current);
        else
            {
            // Add the accounts and ids to the collections
            for (TInt i=0; i < saAccounts->Count(); i++)
                {
                const TSendAsAccount accountId = saAccounts->Account(i);
                emailAccountNames->AppendL(saAccounts->NameFromAccountL(accountId));
                User::LeaveIfError(emailAccountIds.Append(accountId));
                }

            current++;
            }
        }

    // --->
    // for example use CAknListQueryDialog to display the list of email accounts the
    // user can select to send a message
    // <---
    CleanupStack::PopAndDestroy(5, emailAccountNames);


Thats it. Quite simple but more work than I expected for such a simple task.
Next time we will get rid of the "E-mail" hack and replace it with the proper way to do it.

Its now official I hate programming MTM's!

RSSComments

You must login to post comments. Login
 

Rate This

 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxE44onE27tE20eE78pectE20miraclesE20hereE2cE20donE27tE20eE78pectE20solutionsE20toE20worldE27sE20problemsE2eE20ItE20isE20moreE20likelyE20thatE20IE20willE20askE20E5bmyselfE5dE20E71uestionsE20lookingE20forE20aE20alwaysE20elusiveE20answerE2eE20AndE20ofE20courseE3aE20E22AllE20opinionsE20eE78pressedE20inE20thisE20blogE20areE20theE20authorE27sE20ownE20andE20doE20notE20necessarilyE20representE20theE20officialE20viewE20ofE20NokiaE22E2eE20IE20meanE20itE21E20ltomutaE20E7cE2025E20AprilE2cE202008E2021E3a30E20IE27veE20hearE20itE20soE20manyE20timesE20thatE20IE20surpriseE20myselfE20forE20notE20believingE20itE20byE20nowE2eE20BashingE20S60E20isE20byE20nowE20theE20mostE20popularE20sportE2cE20atE20leastE20untilE20theE20OlympicE20GamesE20areE2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fblogsE2eforumE2enokiaE2ecomE2fblogE2flucianE2dtomutasE2dforumE2dnokiaE2dblogE2f2008E2f04E2f25E2fleoE2dlaporteE2dandE2dtheE2dtruthE2daboutE2ds60X qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxE4cucianE20TomutaE27sE20ForumE20NokiaE20BlogE20E7cE20E4ceoE20E4caporteE20knowsE20theE20truthE20aboutE20S60E20E3fX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZBlogContentQ qdcZtypeQUqfntypeZBlogE45ntryQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxE44onE27tE20eE78pectE20miraclesE20hereE2cE20donE27tE20eE78pectE20solutionsE20toE20worldE27sE20problemsE2eE20ItE20isE20moreE20likelyE20thatE20IE20willE20askE20E5bmyselfE5dE20E71uestionsE20lookingE20forE20aE20alwaysE20elusiveE20answerE2eE20AndE20ofE20courseE3aE20E22AllE20opinionsE20eE78pressedE20inE20thisE20blogE20areE20theE20authorE27sE20ownE20andE20doE20notE20necessarilyE20representE20theE20officialE20viewE20ofE20NokiaE22E2eE20IE20meanE20itE21E20ltomutaE20E7cE2025E20AprilE2cE202008E2021E3a30E20IE27veE20hearE20itE20soE20manyE20timesE20thatE20IE20surpriseE20myselfE20forE20notE20believingE20itE20byE20nowE2eE20BashingE20S60E20isE20byE20nowE20theE20mostE20popularE20sportE2cE20atE20leastE20untilE20theE20OlympicE20GamesE20areE2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fblogsE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZcppQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZseriesE5f60QRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZBlogContentQ qfnZtypeQUqfntypeZBlogE45ntryQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZupdatedQDx2008E2d04E2d26X qfnZuserE5ftagQSxs60X qfnZuserE5ftagQSxsymbianE2dcE2bE2bX qmarsZdescriptionQSxE44onE27tE20eE78pectE20miraclesE20hereE2cE20donE27tE20eE78pectE20solutionsE20toE20worldE27sE20problemsE2eE20ItE20isE20moreE20likelyE20thatE20IE20willE20askE20E5bmyselfE5dE20E71uestionsE20lookingE20forE20aE20alwaysE20elusiveE20answerE2eE20AndE20ofE20courseE3aE20E22AllE20opinionsE20eE78pressedE20inE20thisE20blogE20areE20theE20authorE27sE20ownE20andE20doE20notE20necessarilyE20representE20theE20officialE20viewE20ofE20NokiaE22E2eE20IE20meanE20itE21E20ltomutaE20E7cE2025E20AprilE2cE202008E2021E3a30E20IE27veE20hearE20itE20soE20manyE20timesE20thatE20IE20surpriseE20myselfE20forE20notE20believingE20itE20byE20nowE2eE20BashingE20S60E20isE20byE20nowE20theE20mostE20popularE20sportE2cE20atE20leastE20untilE20theE20OlympicE20GamesE20areE2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZBlogContentQ qrdfZtypeQUqfntypeZBlogE45ntryQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ