×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    32

    Need help to send a email using smtp.

    Hi All,

    I am new to MTMs & email usage in s60.
    For one of our self project implementation we have a trigger a email based on certain events.

    To send a email, i went through the wiki.forum.nokia and got one example code to do that.

    http://www.symbian.com/developer/tec...view.html#_top

    I went through the above link and modified few constant values accroding to gmail server. ( server adress, pop3 server address, login name, password ). Like below.

    _LIT(KTextPressAKey, "\n\n Press any key to step through the example");
    _LIT(KExit,"\n\n Press any key to exit the application ");
    _LIT(KCreateMtm,"\n\n Creating a Pop3 client MTM");
    _LIT(KKeyPress,"\n\n Press any key");
    _LIT(KTxtAccountName, "PopAccount");
    _LIT(KCreatePopAccount,"\n\n Creating a Pop account");
    _LIT(KCreateSmtpAccount,"\n\n Creating an Smtp account");
    _LIT(KSmtpServerAddress, "ban-sindhub01.intra");
    _LIT(KEmailAlias, "Messaging example");
    _LIT(KSmtpEmailAddress, "smtp.gmail.com");
    _LIT8(KFrom, "smanikandan14@gmail.com");
    _LIT(KTo, "smani14@gmail.com");

    _LIT(KSubject, "SimpleEmail");
    _LIT(KBodyContents, "This is a very simple mail");
    _LIT(KSendMail,"\n\n Sending the mail... please wait");
    _LIT(KPopServer, "pop.gmail.com");
    _LIT8(KPopPassword,"joliee");
    _LIT8(KPopLoginName,"smanikandan14");

    _LIT(KWait,"\n\n Connecting to pop3 server");
    _LIT(KDownload,"\n\n Downloading mail from the pop3 server");
    _LIT(KDisconnect,"\n\n Press any key to disconnect");

    Then changed the port and made SSL enabled as told in the gmail configurations in the below code

    void CPop3Example::CreatePopAndSmtpAccountL()
    {
    CEmailAccounts* emailAccounts = CEmailAccounts::NewLC();
    CImPop3Settings* settings = new(ELeave) CImPop3Settings();
    CleanupStack::PushL(settings);

    CImIAPPreferences* popIAP = CImIAPPreferences::NewLC();

    // Set the server address to system address
    settings->SetServerAddressL(KPopServer);
    settings->SetLoginNameL(KPopLoginName);
    settings->SetPasswordL(KPopPassword);
    settings->SetSSLWrapper(ETrue);
    settings->SetPort(995);


    // Create a Pop account
    iConsole->Printf(KCreatePopAccount);
    iPopAccount = emailAccounts->CreatePopAccountL(KTxtAccountName, *settings,*popIAP,EFalse);

    CImSmtpSettings *smtpSettings = new (ELeave) CImSmtpSettings();
    CleanupStack::PushL(smtpSettings);

    emailAccounts->PopulateDefaultSmtpSettingsL(*smtpSettings, *popIAP);

    // Create an Smtp acoount
    iConsole->Printf(KCreateSmtpAccount);
    iSmtpAccount = emailAccounts->CreateSmtpAccountL(iPopAccount, *smtpSettings, *popIAP, EFalse);

    emailAccounts->SetDefaultSmtpAccountL(iSmtpAccount);

    smtpSettings->SetServerAddressL(KSmtpServerAddress);
    smtpSettings->SetEmailAliasL(KEmailAlias);
    smtpSettings->SetEmailAddressL(KSmtpEmailAddress);
    smtpSettings->SetReplyToAddressL(KSmtpEmailAddress);
    smtpSettings->SetReceiptAddressL(KSmtpEmailAddress);
    smtpSettings->SetSSLWrapper(ETrue);
    smtpSettings->SetPort(465);


    // Add IAP to the IAP preferences
    CImIAPPreferences* prefs = CImIAPPreferences::NewLC();
    TImIAPChoice iap;
    TInt iapID = 0;
    CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion());
    CleanupStack::PushL(dbSession);
    CCDConnectionPrefsRecord *connPrefRecord = static_cast<CCDConnectionPrefsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord));
    CleanupStack::PushL(connPrefRecord);

    // Set the direction of connection
    connPrefRecord->iDirection = ECommDbConnectionDirectionOutgoing;
    connPrefRecord->iRanking = 1;
    if(!connPrefRecord->FindL(*dbSession))
    {
    User::Leave(KErrNotFound);
    }
    iapID = connPrefRecord->iDefaultIAP;
    iap.iIAP = iapID;
    iap.iDialogPref = ECommDbDialogPrefDoNotPrompt;
    prefs->AddIAPL(iap);

    emailAccounts->GetSmtpAccountL(iSmtpAccount.iSmtpService, iSmtpAccount);
    emailAccounts->SaveSmtpSettingsL(iSmtpAccount,*smtpSettings);
    emailAccounts->SaveSmtpIapSettingsL(iSmtpAccount, *prefs);

    CleanupStack::PopAndDestroy(7,emailAccounts); //connPrefRecord,dbSession,prefs,smtpSettings,popIAP,settings,emailAccounts
    }

    Then i compiled the code as given in that link.

    After execution i could see a new mailbox created under messaging->mailbox.

    And the mail which is sent through this code lies under 'outbox' folder and it is queued. It didnt go to the smtp server.

    Can anyone help in this ? what could be the reason ? is the code in the above exmaple is proper. ?
    Is changing the smtp port number to 465 could cause the problem ? any idea..
    Can anyone share a code which is able to send a email properly without issues.



    Thanks,
    Mani

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Need help to send a email using smtp.

    Quote Originally Posted by smanikandan14 View Post
    Is changing the smtp port number to 465 could cause the problem ?
    Do you have any reason for doing that?

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    32

    Re: Need help to send a email using smtp.

    Yes, the gmail configurations say it to set the port number to 467.
    Pls chk this link.

    http://mail.google.com/support/bin/a...n&answer=13287

    thanks,
    mani

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    165

    Re: Need help to send a email using smtp.

    Quote Originally Posted by wizard_hu_ View Post
    Do you have any reason for doing that?
    Hi wizard_hu

    What do you mean ?? do you mean that isn't the way to enabled the SSL ???

    BTW finally I have succeeded to send a mail with other SMTP server without any SSL

    but i didn't succeed to send it to other mail only to my mail. very strange...

    tnx,
    Dvir.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    32

    Re: Need help to send a email using smtp.

    Hi Dvir,

    Thats a good thing that u can able to send email with that code.
    may i know which smpt server u used... I mean which email server u have used and send email.
    have u used the same code given in the link which i gave ?

    thanks,
    - mani

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    32

    Re: Need help to send a email using smtp.

    Hi...
    Can anyone help me on this... How to send an email to gmail server.?
    Have anyone succeeded in sending mail to gmail.

    Thanks,
    - mani

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    165

    Re: Need help to send a email using smtp.

    Hi smanikandan14 ,

    The example works for me with ISP provider. with Gmail mail, I had a some problems, I think because the SSL.

    I had some problem with the code:
    1. I can't send mail to other mailbox only to my mail box - Wizard_hu think that it's because the SMTP server but I don't think so.
    2. I don't know how to add attachment to the Mail, may be you can help with that ??

    Hope it helpful.
    Dvir.

  8. #8
    Nokia Developer Champion
    Join Date
    May 2004
    Posts
    2,267

    Re: Need help to send a email using smtp.

    Hi,

    See my (working) code in the following post, pay special attention to the lines marked with "<==".

    "Re: Creating a Gmail account "
    http://discussion.forum.nokia.com/fo...01&postcount=2

    Regards

    Ziteng Chen

Similar Threads

  1. How to send email using rsendas and rsendasmessage
    By xhsoldier in forum General Messaging
    Replies: 13
    Last Post: 2006-07-24, 21:13
  2. How to send email using rsendas(I posted, but no one gave me the answer)
    By xhsoldier in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2006-07-05, 09:39
  3. send email with attachment by CSmtpClientMtm
    By sam_jason in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-05-14, 10:05
  4. How to send mail thru SMTP .........
    By ping2sharad in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-05-09, 12:07
  5. Needs to send Ringtones and Logos via email
    By hiteshkaku in forum Smart Messaging
    Replies: 1
    Last Post: 2002-11-22, 06:30

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×