Archived:Sending an e-mail using CSendAs
Article Metadata
Compatibility
Article
Description
The following code demonstrates how to send an e-mail programmatically using CSendAs.
MSendAsObserver is an observer that allows the client application to receive notifications about capability checks. The client application must implement this interface in order to receive notifications.
Derive the MSendAsObserver mixin class and implement the callback function CapabilityOK():
class CMyEmailEngine : public MSendAsObserver
{
...
public:
// from MSendAsObserver
TBool CapabilityOK(TUid aCapability, TInt aResponse);
...
private:
CSendAs* iSendAs;
CRichText* iRichText;
CParaFormatLayer* iParaLayer;
CCharFormatLayer* iCharLayer;
};
Sending an e-mail
The following code snippet can be used to send an e-mail using CSendAs:
iParaLayer=CParaFormatLayer::NewL();
iCharLayer=CCharFormatLayer::NewL();
//For creating the content of the mail
iRichText=CRichText::NewL(iParaLayer,iCharLayer);
//KBody is the content to be sent
iRichText->InsertL(0,KBody);
iSendAs->SetMtmL(KUidMsgTypeSMTP);
//Create the mesage in outbox.
iSendAs->CreateMessageL(KMsvGlobalOutBoxIndexEntryId);
//Set the subject of the mail
iSendAs->SetSubjectL(_L("First Email"));
//Add the recipient of the mail
//KRecipient is recievers mail address
iSendAs->AddRecipientL(KRecepient);
//Set the text of the message
iSendAs->SetBodyL(*iRichText);
//Save the message
iSendAs->SaveMessageL(ETrue);
Note that the e-mail is not sent immediately and remains in the outbox. The e-mail is sent by smtp MTM only when a new connection has been established with the remote server. The new connection can be established as follows:
1) Opening the messaging application and using the "Send" option (which you have used)
2) If the "automatic retrieval" option in mail settings is "ON", the connection is established according to the rules specified for the automatic retrieval of e-mails.

