Login  
Search All Forums
Dart Home | PowerTCP Mail for ActiveX | Custom Development Reply | PowerTCP Mail for ActiveX Topics | Forums   
AuthorForum: PowerTCP Mail for ActiveX
Topic: Using DartSMTP in a class
Jarrod

From: Burlington, KY USA
Posts: 2
Member Since: 09/13/02
posted September 13, 2002 2:25 PM

All the examples I see use Dart Mail Tool in a form. Forms are persistent and hang around, unlike classes. I need to use it in a class and let the SMTP1_Progress event run before the class runs all its code and terminates. How can I keep the class from terminating before the event occurs?
Jon Belanger



From: Rome, NY USA
Posts: 310
Member Since: 06/10/02
posted September 13, 2002 3:47 PM

Hello,

  I've put together some sample code to illustrate how this is done in VB..

Private WithEvents smtp1 As DartMail.Smtp

Private Sub Class_Initialize()

  Set smtp1 = New DartMail.Smtp
  
  smtp1.Timeout = 0
  Dim msg As New Message
  
  msg.Text = "hello"
  msg.From = "me@me.com"
  msg.To.Add "foo@foo.com"
  msg.Subject = "Hello"
  
  smtp1.Message = msg
  
End Sub

Public Sub Login()

  Debug.Print "Logging In..."
  smtp1.Login "mail"

End Sub

Private Sub Class_Terminate()
  Debug.Print "Going away now"
End Sub

Private Sub smtp1_Progress(ByVal Method As DartMail.SmtpMethodConstants, ByVal Status As DartMail.SmtpStatusConstants, ByVal Reply As String, ByVal Count As Long, ByVal Size As Long)
  
  Debug.Print Status
  Debug.Print Method
  
  If Method = smtpLogin And Status = smtpOk Then
    smtp1.Send
  ElseIf Method = smtpSend And Status = smtpOk Then
    smtp1.Logout
  End If
  
End Sub

This is an example of using our SMTP control in non-blocking mode within a class. The problem that I think you were seeing is that if you instantiate the class within an event, say a command button click, like this...

Private Sub Command1_Click()

  dim c as class1

  Set c = New Class1
  
  c.Login
  
End Sub


The object 'c' will be destroyed when the event exits, which in this case happens immediately. If you keep the object at a global level like this...

Public c As Class1

Private Sub Command1_Click()

  Set c = New Class1
  
  c.Login
  
End Sub

It works fine, and the object won't be immediately destroyed. Hope that helps.
Jarrod

From: Burlington, KY USA
Posts: 2
Member Since: 09/13/02
posted September 13, 2002 3:58 PM

I appreciate your reply. Here is a little more info on our app and the problem I am having. Our app is a web app. We use ServerXMLHTTP to make a web page call. That web page in turn calls a DLL, which calls another DLL, which calls another DDL, ect... Our Email.dll uses Dart and it is where this problem is. We have no VB forms or EXEs at all in this part of the app. A single com function call goes to the Email.dll. I need a way to make this DLL not terminate before the progress event runs because we want to do not want to use blocking. However, when not blocking, the code finshes before the event and the DLL terminates. I hope this makes sense. If you have any more help it would be greatly appreciated.

Jarrod
Jon Belanger



From: Rome, NY USA
Posts: 310
Member Since: 06/10/02
posted September 13, 2002 5:36 PM

The above posting is still a valid explaination for your situation. If you instantiate a class locally it will terminate when you exit the subroutine that is local to that specific instantiation. As long as the object you instantiated isn't terminated by VB the events in the class will fire.

  If you need further assistance you can contact Dave Harry at support@dart.com and ask about our support options.
Reply | PowerTCP Mail for ActiveX Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX