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!
 
 

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: qdcZrelationQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fschemasE2fnokiaE2fFNE2d1E2e58E2eowlX qdcZtitleQSxForumE20NokiaE20BlogsE20WebE20SiteXLen qdcZtitleQSxForumE20NokiaE20BlogsE20WebE20SiteXLen qdcZtypeQUqfnZE44istributionQ qdcZtypeQUqfnZSiteQ qdcZtypeQUqvocZTermQ qdcZtypeQUqvocZVocabularyConstructQ qdcZtypeQUqwebZSiteQ qdcZtypeQUqrdfsZE52esourceQ qswZserviceQUxhttpE3aE2fE2fswE2enokiaE2ecomE2furiE71aX quriE71aZserviceQUxhttpE3aE2fE2fswE2enokiaE2ecomE2furiE71aX qvocZpartOfQUqfnZPublicationQ qwebZserviceQUxhttpE3aE2fE2fswE2enokiaE2ecomE2furiE71aX qrdfZtypeQUqfnZE44istributionQ qrdfZtypeQUqfnZSiteQ qrdfZtypeQUqvocZTermQ qrdfZtypeQUqvocZVocabularyConstructQ qrdfZtypeQUqwebZSiteQ qrdfZtypeQUqrdfsZE52esourceQ qrdfsZisE44efinedByQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fschemasE2fnokiaE2fFNE2d1E2e58E2eowlX qrdfsZlabelQSxForumE20NokiaE20BlogsE20WebE20SiteXLen qrdfsZlabelQSxForumE20NokiaE20BlogsE20WebE20SiteXLen qrdfsZseeAlsoQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fschemasE2fnokiaE2fFNE2d1E2e58E2eowlX