locked
New System.Net.Mail.MailMessage -An error occurred creating the configuration section handler for system.net/mailSettings/smtp

    Question

  • Hello,

       I am trying to send an email with the System.net.mail.MailMessage object in .NET 2.0, when doing this :

     

    Dim message As New System.Net.Mail.MailMessage

     

    I am getting the Exception :

     

    18/12/2007 1:30:14 PM,System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for system.net/mailSettings/smtp: An error occurred while attempting to impersonate.  Execution of this request cannot continue. ---> System.Web.HttpException: An error occurred while attempting to impersonate.  Execution of this request cannot continue.
       at System.Web.ImpersonationContext.GetCurrentToken()
       at System.Web.ImpersonationContext.ImpersonateToken(HandleRef token)
       at System.Web.ApplicationImpersonationContext..ctor()
       at System.Web.Configuration.WebConfigurationHost.Impersonate()
       at System.Configuration.BaseConfigurationRecord.Impersonate()
       at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
       --- End of inner exception stack trace ---
       at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
       at System.Configuration.BaseConfigurationRecord.CreateSectionDefault(String configKey, Boolean getRuntimeObject, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
       at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
       at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey)
       at System.Configuration.ConfigurationManager.GetSection(String sectionName)
       at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
       at System.Net.Configuration.SmtpSectionInternal.GetSection()
       at System.Net.Mail.MailMessage..ctor()

     

    Any ideas on what is going on ?

     

    Thanks.  Martin

    Tuesday, December 18, 2007 6:01 PM

All replies

  • Hi,

     

    Not 100% sure, are you specifing username + password attributes on the system.net/mailsettings config section? Are they are correct?

     

    Regards Ebo

    Wednesday, December 19, 2007 12:40 AM
  • Ok, here is what I found: if I have <identity impersonate="true"/> in my web.config file and before creating a new MailMessage (Dim message As New System.Net.Mail.MailMessage) object, I impersonate another user, I am getting this exception.

     

    However, if I remove the <identity impersonate="true"/> from my web.config, it works. Can somebody explain to me the behaviour of this ?

     

    Regards,

     

    Martin

     

     

    Wednesday, December 19, 2007 12:35 PM