Author |
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 05 November 2008 at 6:58am | IP Logged
|
|
|
Hi all,
i have a problem with the following code, i doen't know where i can find a "right" error message, to fix this problem
i'm search the hole day (maybe not good enough )
Here my sourcecode :
Code:
Dim mail As MailMessage = New MailMessage
Try
Dim mailMime As Smime = New Smime
Dim mailer As New Smtp
Dim signCert As Certificate = New Certificate("C:\Inetpub\cert.pfx", CertFileType.Pfx, "password")
mail.From.Email = "pr@mail.com"
mail.To.Add("priehmers@mail.com", "")
mail.Subject = "Test Mail"
mail.BodyPlainText = "Test Mail"
mailer.SmtpServers.Add("smtp.mail.com", "pr@mail.com", "password")
mailer.Message = mailMime.Sign(mail, signCert)
mailer.Send()
Label1.Text = "Mail Send!"
mailer.Dispose()
mail.Dispose()
Catch ex As MailBeeCertificateStoreWin32Exception
Label1.Text = ex.Source & "<br><br>" & ex.Message & "<br><br>" & ex.StackTrace & "<br><br>" & ex.NativeErrorCode
End Try
|
|
|
Here the errormessage:
Source
MailBee.NET
Message
Win32 function related to certificate store API returned an error. See NativeErrorCode property value for more information. The Win32 error code is: -2147024894.
StackTrace
bei MailBee.Security.CertificateStore.a(Byte[] A_0, String A_1) bei MailBee.Security.Certificate.a(Byte[] A_0, String A_1) bei MailBee.Security.Certificate.a(Byte[] A_0, CertFileType A_1, String A_2) bei MailBee.Security.Certificate..ctor(String filename, CertFileType fileType, String pfxFilePassword) bei test.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\test.aspx.vb:Zeile 6. (Line 6)
NativeErrorCode
-2147024894
Line 6 : Dim signCert As Certificate = New Certificate("C:\Inetpub\cert.pfx", CertFileType.Pfx, "password")
I hope you can help me, by this strange error. If you need more information, please let me know.
thanks you much!
Patrick
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 05 November 2008 at 7:26am | IP Logged
|
|
|
The error code -2147024894 corresponds to the error message "The system cannot find the file specified."
Please check if you have specified filename properly and if the system can read the file, try setting "Read" permissions to "Everyone" user over the file.
We recommend you to place the certificate file in any other folder, as C:\Inetpub folder is used by IIS and is not intended for storing certificates.
Regards,
Igor
|
Back to Top |
|
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 05 November 2008 at 8:03am | IP Logged
|
|
|
Hi Igor,
thanks for your answer!
I do you tips, create a folder with write/read permissions for the user "everyone" and copy the .pfx file in there. In my code i change the path to it, but i get the "same" errormessage.
Code:
Dim mail As MailMessage = New MailMessage
Try
Dim mailMime As Smime = New Smime
Dim mailer As New Smtp
Dim signCert As Certificate = New Certificate("C:\certs_files\cert.pfx", CertFileType.Pfx, "password")
mail.From.Email = "pr@mail.com"
mail.To.Add("priehmers@mail.com", "")
mail.Subject = "Test Mail"
mail.BodyPlainText = "Test Mail"
mailer.SmtpServers.Add("smtp.mail.com", "pr@mail.com", "password")
mailer.Message = mailMime.Sign(mail, signCert)
mailer.Send()
Label1.Text = "Mail Send!"
mailer.Dispose()
mail.Dispose()
Catch ex As MailBeeCertificateStoreWin32Exception
Label1.Text = ex.Source & "<br><br>" & ex.Message & "<br><br>" & ex.StackTrace & "<br><br>" & ex.NativeErrorCode
End Try
|
|
|
NativeErrorCode
-2147024894
do you know, what can be the problem??
thank you very much igor!
patrick
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 05 November 2008 at 8:20am | IP Logged
|
|
|
Can you read the same file with other methods? For instance, try to read it with System.IO.StreamReader class just prior to "Dim signCert As Certificate = New Certificate" line.
If it cannot be read too, the problem is not linked to MailBee (the file is missing or not accessible).
Regards,
Alex
|
Back to Top |
|
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 05 November 2008 at 11:36pm | IP Logged
|
|
|
Hallo Alex,
thanks for your reply, i do, what you write, but the errormessage is still the same. The error is not more an line 6, now line 7.
Code:
Dim mail As MailMessage = New MailMessage
Try
Dim mailMime As Smime = New Smime
Dim mailer As New Smtp
Dim testobj As New StreamReader("C:\certs_files\cert.pfx")
Dim signCert As Certificate = New Certificate("C:\certs_files\cert.pfx", CertFileType.Pfx, "password")
mail.From.Email = "pr@mail.com"
mail.To.Add("priehmers@mail.com", "")
mail.Subject = "Test Mail"
mail.BodyPlainText = "Test Mail"
mailer.SmtpServers.Add("smtp.mail.com", "pr@mail.com", "password")
mailer.Message = mailMime.Sign(mail, signCert)
mailer.Send()
Label1.Text = "Mail Send!"
mailer.Dispose()
mail.Dispose()
Catch ex As MailBeeCertificateStoreWin32Exception
Label1.Text = ex.Source & "<br><br>" & ex.Message & "<br><br>" & ex.StackTrace & "<br><br>" & ex.NativeErrorCode
End Try
|
|
|
Without line 7, the mail was send.
thanks for your help,
Patrick
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 05 November 2008 at 11:56pm | IP Logged
|
|
|
Have you tried to actually read that file? Something like:
Best regards,
Andrew
|
Back to Top |
|
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 06 November 2008 at 12:09am | IP Logged
|
|
|
Hello Andrew,
yes, its no problem, to open it with the Streamreader class.
Btw, i use the newst version 4.0.2.105, downloaded from you homepage.
thanks,
Patrick
|
Back to Top |
|
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 06 November 2008 at 1:21am | IP Logged
|
|
|
Hi all,
i try something others, what returns the same errormessage/nativecode "-2147024894"
Code:
Dim mail As MailMessage = New MailMessage
Try
Dim mailMime As Smime = New Smime
Dim mailer As New Smtp
Dim testobj As New StreamReader("C:\certs_files\cert.pfx")
Dim testCert As Byte() = GetStreamAsByteArray(testobj.BaseStream)
Dim signCert As Certificate = New Certificate("C:\certs_files\cert.pfx", CertFileType.Pfx, "password")
mail.From.Email = "pr@mail.com"
mail.To.Add("priehmers@mail.com", "")
mail.Subject = "Test Mail"
mail.BodyPlainText = "Test Mail"
mailer.SmtpServers.Add("smtp.mail.com", "pr@mail.com", "password")
mailer.Message = mailMime.Sign(mail, signCert)
mailer.Send()
Label1.Text = "Mail Send!"
mailer.Dispose()
mail.Dispose()
' ----------------
Function GetStreamAsByteArray(ByVal stream As System.IO.Stream) As Byte()
Dim streamLength As Integer = Convert.ToInt32(stream.Length)
Dim fileData As Byte() = New Byte(streamLength) {}
stream.Read(fileData, 0, streamLength)
stream.Close()
Return fileData
End Function
|
|
|
I hope it helps, to help me
thank you very much guys.
Patrick
|
Back to Top |
|
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 06 November 2008 at 1:23am | IP Logged
|
|
|
soorryyy...
WRONG:
Code:
Dim signCert As Certificate = New Certificate("C:\certs_files\cert.pfx", CertFileType.Pfx, "password")
|
|
|
RIGHT
Code:
Dim signCert As Certificate = New Certificate(testCert, CertFileType.Pfx, "password")
|
|
|
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 06 November 2008 at 5:22am | IP Logged
|
|
|
We couldn't reproduce the issue in our environment with our test PFX files.
Please download this sample application and run runme.bat. It reads the sample pfx file shipped with the application and displays e-mail address the certificate issued to.
If it works fine in your environment, please run the same application with your certificate which causes the issue. To do this, copy your certificate to the application folder and change name and password in the runme.bat with values appropriate for your PFX file.
Please let us know if the same application works fine with your PFX file.
Best regards,
Andrew
|
Back to Top |
|
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 06 November 2008 at 5:48am | IP Logged
|
|
|
Hi Andrew,
I tested your tool with 2 different pfx files and the output was the correct emailaddress of the pfx certs.
Your Tool works correctly with my pfx files.
thank you for your reply.
Patrick
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 06 November 2008 at 5:59am | IP Logged
|
|
|
Please try to remove the reference to MailBee.NET.dll from your project and add a new one to the MailBee.NET.dll you've downloaded along with the sample application. Alternatively, you can download that version here.
Best regards,
Andrew
|
Back to Top |
|
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 06 November 2008 at 6:04am | IP Logged
|
|
|
Hi Andrew,
i make a test, with a new created console application, with the same code from my aspx file...and look, its works fine
i think its a ntfs permission problem, but i doen't understand why. The user "everyone" have full-rights of the complete folder-tree!
Ok i look forward to the permission and thank you very very much for your help Andrew, Igor and Alex!!
Have a nice day, greez from Switzerland
Patick
|
Back to Top |
|
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 06 November 2008 at 7:52am | IP Logged
|
|
|
Hey guys,
i come back to you and hope you have some good idea's for my problem.
The errormessage is still the same!
I give my IUSER full control of the complete "inetpub" folder and spezialy to the pfx files. I try to give the Certificate methode not the direct pfx file but i give this methode the byte-array of the pfx file, like my 4th post in this thread.
I try my console application with the permission (runas command) of my spezial IUSER, the same path to the pfx file as in my web application. This works fine and signed my generated email.
Andrew, I do your tipp with the dll, download it and add it in the VS Project.
i'm at the end with my knowledge and hope you have a good idea, what can be wrong there!
thanks very much for your help guys!!
Patrick
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 07 November 2008 at 12:56am | IP Logged
|
|
|
Usually, ASP.NET applications are running under NETWORK SERVICE or ASP.NET system accounts, not under IUSER.
This topic of WebMail Pro ASP.NET FAQ would be helpful to you.
Best regards,
Andrew
|
Back to Top |
|
|
PRiehmers Newbie
Joined: 05 November 2008 Location: Switzerland
Online Status: Offline Posts: 10
|
Posted: 07 November 2008 at 4:16am | IP Logged
|
|
|
Hi all,
really thanks for your help with my email signing problem. I found the solution!
This "little" config-entry in my web.config makes the error:
<identity impersonate="true"/>
Without this entry, its works fine and without problems! I doen't really understand why, but not it works!
If you know the matter, why it doesn't work with this setting, feel free to reply ;)
thanks alot for your help and idea's!!
greez
Patrick
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 07 November 2008 at 4:28am | IP Logged
|
|
|
That setting makes your ASP.NET application to run under user account you're currently logged under. I.e. your web browser passes your current identity (username and password hash) from your local machine to IIS which runs the ASP.NET application under that username. That's why granting rights to ASP.NET and NETWORK SERVICE accounts didn't solve the issue.
Best regards,
Andrew
|
Back to Top |
|
|