[VB6] AspEncrypt en signed e-mail

Pagina: 1
Acties:

  • Ashtaroth
  • Registratie: December 2003
  • Laatst online: 16-02 09:59
Ik probeer middels VB6 en AspEncrypt een signed e-mail te versturen, maar loop tegen een foutmelding aan die ik niet kan verklaren. Misschien dat een van jullie ervaring hiermee heeft.

De foutmelding gebeurt op regel 360 (zie code) en luidt: Cannot find object or property.

Probleem is dat ik niet kan debuggen op de machine waar de certificaten staan geinstalleerd. De parameters staan in een config bestandje, zodat ik e.e.a. kan uitproberen en wijzigen. Echter, tot op heden is t me nog steeds niet gelukt signed te mailen. Ik vermoed dat t probleem ligt bij het aanmaken van het context object, maar snap dan alleen niet waarom? Ik hoop dat iemand mij hierbij kan helpen.

Dan de code:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Public Function SendEmail(ByVal p_strCertificatePathEncrypt As String, ByVal p_strCertificatePathSign As String, _
                          ByVal p_strContainerName As String, ByVal p_blnIsMachineKey As Boolean, _
                          ByVal p_strSMTPServer As String, ByVal p_lngSMTPPort As Long, _
                          ByVal p_strMailFrom As String, ByVal p_strMailFromDisplay As String, _
                          ByVal p_strMailTo As String, ByVal p_strSubject As String, _
                          ByVal p_strUserName As String, ByVal p_strPassword As String, _
                          ByVal p_strAttachmentPath As String, ByVal p_blnIsMember As Boolean) As Boolean
10    On Error GoTo Catch

          Dim objCryptManager         As ASPENCRYPTLib.CryptoManager
          Dim objContext              As ASPENCRYPTLib.ICryptoContext
          Dim objSignerCertificate    As ASPENCRYPTLib.ICryptoCert
          Dim objRecipientCertificate As ASPENCRYPTLib.ICryptoCert
          Dim objSignerMessage        As ASPENCRYPTLib.ICryptoMessage
          Dim objRecipientMessage     As ASPENCRYPTLib.ICryptoMessage
          Dim objMail                 As ASPEMAILLib.MailSender
          Dim blnIsSent               As Boolean
          Dim strMailType             As String
    
          '\\ All e-mails are sent signed.
          '\\ E-mails to members are also sent encrypted.
20        Set objCryptManager = New ASPENCRYPTLib.CryptoManager
    
          '\\ If AspEncrypt is to run in the context of a non-interactive user
          '\\ (such as in an ASP or ISAPI application) you should set the Boolean
          '\\ parameter to True
      '                Set objContext = objCryptManager.OpenContext("MyContainer", False)
30        Set objContext = objCryptManager.OpenContext(p_strContainerName, p_blnIsMachineKey)
    
40        If Not p_blnIsMember Then
              ' Obtain recipient certificate."
50            Set objRecipientCertificate = objCryptManager.ImportCertFromFile(p_strCertificatePathEncrypt)
        
              ' Create and configure CryptoMessage object.
60            Set objRecipientMessage = objContext.CreateMessage
70            Call objRecipientMessage.AddRecipientCert(objRecipientCertificate)
80            If g_blnIsDebugMode Then Call LogError(0, "Encrypt certificate added", _
                                                     COMP_NAME & "." & CLASS_NAME & ".ProcessEmail()", vbLogEventTypeInformation)
90            strMailType = "encrypted"
100       End If
    
          '\\ Obtain Signer certificate.
110       Set objSignerCertificate = objCryptManager.ImportCertFromFile(p_strCertificatePathSign)
    
          '\\ Create and configure CryptoMessage object.
120       Set objSignerMessage = objContext.CreateMessage
130       Call objSignerMessage.SetSignerCert(objSignerCertificate)
140       If g_blnIsDebugMode Then Call LogError(0, "Sign certificate added", _
                                                 COMP_NAME & "." & CLASS_NAME & ".ProcessEmail()", vbLogEventTypeInformation)
    
150       If Len(strMailType) = 0 Then
160           strMailType = "signed"
170       Else
180           strMailType = "signed and " & strMailType
190       End If
200       If g_blnIsDebugMode Then Call LogError(0, "Sending " & strMailType & " email to " & p_strMailTo, _
                                                 COMP_NAME & "." & CLASS_NAME & ".ProcessEmail()", vbLogEventTypeInformation)
    
          '\\ Configure e-mail message.
210       Set objMail = New ASPEMAILLib.MailSender
220       With objMail
              '\\ Set e-mail properties.
230           .Host = p_strSMTPServer
240           .Port = p_lngSMTPPort
250           .Subject = p_strSubject
260           Call .AddAddress(p_strMailTo)
270           .From = p_strMailFrom
280           .FromName = p_strMailFromDisplay
290           .Subject = p_strSubject
300           If Len(p_strUserName) <> 0 Then
310             .Username = "p_strUserName"
320             .Password = "p_strPassword"
330           End If
              '\\ Set and add attchment.
340           Call .AddAttachment(p_strAttachmentPath)
              ' Send Signed (and Encrypted) e-mail message.
350           If p_blnIsMember Then
360               Call .SendSigned(objSignerMessage)
370               If g_blnIsDebugMode Then Call LogError(0, "Send signed email", _
                                                         COMP_NAME & "." & CLASS_NAME & ".ProcessEmail()", vbLogEventTypeInformation)
380           Else
390               Call .SendSignedAndEncrypted(objSignerMessage, objRecipientMessage)
400                If g_blnIsDebugMode Then Call LogError(0, "Send signed and encrypted email", _
                                                          COMP_NAME & "." & CLASS_NAME & ".ProcessEmail()", vbLogEventTypeInformation)
410           End If
420       End With
    
430       blnIsSent = True
    
Finally:
440       Set objMail = Nothing
450       Set objRecipientMessage = Nothing
460       Set objSignerMessage = Nothing
470       Set objRecipientCertificate = Nothing
480       Set objSignerCertificate = Nothing
490       Set objContext = Nothing
500       Set objCryptManager = Nothing
510       SendEmail = blnIsSent
520       Exit Function

Catch:
530       blnIsSent = False
540       With Err
550           Call LogError(.Number, .Description, COMP_NAME & "." & CLASS_NAME & ".SendEmail() line " & CStr(Erl), vbLogEventTypeError)
560       End With
570       Resume Finally
End Function


Misschien dat de code wat beter kan, maar "first make it work", daarna verbeteren.
Thnx

Verwijderd

Ik heb hier zo geen VS bij de hand, maar weet je zeker dat de propertie naam goed is?

edit:

objSignerMessage al op NULL gecontrolleerd?

[ Voor 28% gewijzigd door Verwijderd op 17-12-2003 13:41 ]


  • Ashtaroth
  • Registratie: December 2003
  • Laatst online: 16-02 09:59
Property name is correct.

Indien objSignerMessage Null zou zijn, zou m.i. de code op regel 130 een fout moeten geven. Maar ik ga 't i.i.g. ff controleren op Null, niet geschoten is altijd mis.

Thnx.

Verwijderd

Weet je toevallig van welke exception class de error is?

  • Ashtaroth
  • Registratie: December 2003
  • Laatst online: 16-02 09:59
De volledige regel in mijn log file is als volgt:

[Error] Cannot find object or property.
(38) in MailHelper.SendEmail() line 640 original source 0

Tussen haakjes staat het foutnummer.
Original source is het resultaat van het uitvragen van LastDllError aan 't Error object.

BTW: Het regel nummer is nu 640 i.p.v. 360, omdat ik op een aantal plekken uitvraag of de objecten Null zijn, wat overigens niet het geval is.