Creates and initializes a licensed EMail object at runtime.
Type | Description | |||
An EMail object being created |
The NewEMail property must be used to create licensed EMail objects at runtime. If your application uses CreateObject or the New operator to instantiate Email objects, it will only run on systems where ExEMail is already licensed. On machines without a license, those methods will fail, and the objects cannot be created. To avoid this limitation and ensure your application works on any deployment system, always use the NewEMail and NewMessage properties to generate licensed objects at runtime.
In isolated applications, however, the NewEmail and NewMessage properties cannot be used. In this case, you must instantiate the objects directly using their CLSIDs:
The following VB6 example shows how to implement a CreateFromCLSID function that uses Windows API calls (CLSIDFromString and CoCreateInstance) to create COM objects by CLSID:
Private Declare Function CLSIDFromString Lib "ole32" (ByVal s As Long, ByRef id As Any) As Long Private Declare Function CoCreateInstance Lib "ole32" (ByRef clsid As Any, ByVal pUnk As Long, ByVal ctx As Long, ByRef iid As Any, ByRef obj As Any) As Long Public Function CreateFromCLSID(s As String) As Object Dim c(15), i(15), o As Object CLSIDFromString StrPtr(s), c(0) CLSIDFromString StrPtr("{00000000-0000-0000-C000-000000000046}"), i(0) ' IID_IUnknown If CoCreateInstance(c(0), 0, 1, i(0), o) = 0 Then Set CreateFromCLSID = o End Function
The following sample shows how to send an email using blocking mode:
Private Sub Form_Load() Dim m As Message Set m = Runtime1.NewMessage If (0 = m.Send("me", "mike1@Unknown2.com,mike2@Unknown2.com,mike3@Unknown2.com", "Hello")) Then MsgBox "The message was delivered OK." End If End Sub
The following sample shows how to send an email using non-blocking way:
Dim WithEvents e As EMail Private Sub e_EndSend(ByVal Msg As EXEMAILLibCtl.IMessage) If (Msg.LastError = 0) Then MsgBox "The message was delivered OK." End If Debug.Print e.Error(Msg.LastError) End Sub Private Sub Form_Load() Set e = Runtime1.NewEMail Dim m As Message Set m = Runtime1.NewMessage Set m.Notifier = e m.Send "me", "mike1@Unknown2.com,mike2@Unknown2.com,mike3@Unknown2.com", "Hello" End Sub