Click to See Complete Forum and Search --> : sending email with vb


jan s.
September 4th, 2001, 05:09 AM
Hi.
i tried to send an email with vb, but failed.
i used the following code:

Private Sub Command1_Click()
Dim myMail
Set myMail = CreateObject("CDONTS.NewMail")
myMail.From = "Example@Microsoft.com"
myMail.To = "x@y.z"
myMail.Subject = "Sample Message"
myMail.Body = "This is a sample message."
myMail.AttachFile "c:\sample.txt"
myMail.Send
Set myMail = Nothing
End Sub

I always get an error message like
Active-x component cannot create objects

Can anyone please help me?

Thank you

PS: Can anyone send me the sample programm "vbmail.vbp". It wasnt included in my version of vb.

berta
September 4th, 2001, 05:20 AM
have U installed option pack 4?

<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>

bhanuprakash
September 4th, 2001, 05:26 AM
Hi,
Creating objects requires that the object'sclass be registered in the systemregistry and that any associateddynamic-link libraries (DLL) be available. This error has the following causes and solutions:

The class isn't registered. For example, the system registry has no mention of the class, or the class is mentioned, but specifies either a file of the wrong type or a file that can't be found.
If possible, try to start the object's application. If the registry information is out of date or wrong, the application should check the registry and correct the information. If starting the application doesn't fix the problem, rerun the application's setup program.

A DLL required by the object can't be used, either because it can't be found, or it was found but was corrupted.
Make sure all associated DLLs are available. For example, the Data Access Object (DAO) requires supporting DLLs that vary among platforms. You may have to rerun the setup program for such an object if that is what is causing this error.

The object is available on the machine, but it is a licensedAutomation object, and can't verify the availability of the license necessary to instantiate it.

enigmaos
September 4th, 2001, 08:01 AM
This sample uses MAPI. Make sure you have Outlook installed. I also posted a "SMTP/POP3" sample for your other question: "Email without MAPI" if this is not what you needed.


'Create MAPI Session
set objsession = CreateObject("MAPI.session")
'Login using the default username
objSession.Logon "", "", false, false, 0
'Create message object
set objNewMessage = objsession.Outbox.Messages.Add
'Create recipient object
set objRecipient = objNewMessage.Recipients.Add
'Create attachment object
set objAttachment = objNewMessage.Attachments.Add

objRecipient.Name = abc@test.com
objNewMessage.Subject = "Test Subject"
objNewMessage.Text = "Test Message"
objAttachment.Source = FileName & FileExtension
objAttachment.Name = FileName & FileExtension
objAttachment = Path & Filenumber & FileExtension
objRecipient.Resolve
objNewMessage.Update
objNewMessage.Send
objSession.Logoff




enigmaos@yahoo.com

bhaskarreddy
September 4th, 2001, 11:22 PM
use the following code in the module

Option Explicit
Public Const EMAIL = "info@neongate.com"
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Const SW_SHOWNORMAL = 1
Public Sub sendemail()
Dim Success As Long
Success = ShellExecute(0&, vbNullString, "mailto:" & EMAIL, vbNullString, "C:\", SW_SHOWNORMAL)
End Sub


and use this code in the application form

onclick event --->
sendmail