|
-
Mar 23rd, 2008, 12:27 PM
#1
Thread Starter
Fanatic Member
How to send E-Mail with VB6
Can someone explain to me how can i send e mail to a single address written in a textbox.
I found this example but it doesnt work for me. I get an error saying Object required. What do i need to do. Could someone please write the whole code to send an e-mail massage (with all assignments and declarations). I dont know what class must i assign to object to work with following commands .
Code:
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
'Compose new message
MAPIMessages1.Compose
'Address message
MAPIMessages1.RecipDisplayName = "Name"
MAPIMessages1.RecipAddress = [email protected]
' Resolve recipient name
MAPIMessages1.AddressResolveUI = True
MAPIMessages1.ResolveName
'Create the message
MAPIMessages1.MsgSubject = "Subject"
MAPIMessages1.MsgNoteText = "Message text"
'Add attachment
MAPIMessages1.AttachmentPathName = "file path"
'Send the message
MAPIMessages1.Send False
MAPISession1.SignOff
For example, i want when i click on button (Command1) to send an e mail to a certain address. Do i need SMTP Host address and if i do, i would need address that i can use. I would be grateful if someone can provide an SMTP adress too .
-
Mar 23rd, 2008, 12:46 PM
#2
Member
Re: How to send E-Mail with VB6
SMTP host is the server address used by your internet service provider.
You can contact your internet service provider for this detail.
You need to add MAPI OCX by going to reference window..
Ashish
-
Mar 23rd, 2008, 01:24 PM
#3
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
 Originally Posted by ashishprem
SMTP host is the server address used by your internet service provider.
You can contact your internet service provider for this detail.
You need to add MAPI OCX by going to reference window..
Ashish
But in this code above there isnt a command to add SMTP host. Btw, i cant find MAPI OCX. Im looking in Project->References.
How can i add it?
-
Mar 23rd, 2008, 02:35 PM
#4
Member
Re: How to send E-Mail with VB6
you can go in references and then select browse and select this OCX file...MSMAPI32.OCX
probably it should be in windows\system32 folder.
Regarding the uasge SMTP details in MAPI code. i believe it uses the outlook configured SMTP..
-
Mar 23rd, 2008, 02:39 PM
#5
Member
Re: How to send E-Mail with VB6
you need to assign the outlook profile name in the code
-
Mar 23rd, 2008, 02:51 PM
#6
Member
Re: How to send E-Mail with VB6
when i googled i found one sample... it might helps..
http://www.devarticles.com/c/a/Visua...isual-Basic/2/
-
Mar 23rd, 2008, 04:40 PM
#7
Re: How to send E-Mail with VB6
to use Mapi you need to have a mapi compliant email client such as outlook installed, outlook express is not suitable
there are several ways to send emails, one of the best is vbsendmail, or you can try cdo like this
vb Code:
Set objEmail = CreateObject("CDO.Message") objEmail.From = "your email here" objEmail.To = text1.text objEmail.Subject = "subject of email" objEmail.Textbody = "a message to send" objEmail.Send
this may work directly as it will try to use your default settings, otherwise you may need to set the configuation for the cdo object, see this post http://www.vbforums.com/showpost.php...08&postcount=8
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 23rd, 2008, 04:54 PM
#8
Re: How to send E-Mail with VB6
i will go with westconn. vbsendmail is the best.
-
Mar 23rd, 2008, 06:11 PM
#9
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
Thanks guys. Ill try it now
-
Mar 23rd, 2008, 06:15 PM
#10
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
I doesnt work for me. I think i must configure it as you said.
Well, i have my mail via Yahoo. mail.yahoo.com.
Can this solution still work for me?
Code:
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
Ive red this code you provided. What type of object must i create for this?
-
Mar 23rd, 2008, 06:35 PM
#11
Re: How to send E-Mail with VB6
same object as you create to send the email, just they call it objectmessage in this example
as i don't need to configure it to work from here i don't have much experience with this side of it, but if you are going to use on other machines it will always be necessary to configure
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 24th, 2008, 12:28 AM
#12
Member
Re: How to send E-Mail with VB6
I have attached the vbsendmail email application. It works perfectly for me.
May be you can also make use of it.
Ashish
Last edited by ashishprem; Mar 24th, 2008 at 06:09 AM.
-
Mar 24th, 2008, 05:49 AM
#13
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
-
Mar 24th, 2008, 06:00 AM
#14
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
I get an error saying:
The message could not be sent to SMTP server. The transport error code was 0x800ccc67. The server response was 421 cannot connect to SMTP server 'here goes IP adress', connect error 10060
-
Mar 24th, 2008, 06:06 AM
#15
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
I fixed that but now i get "530 Authentication required"
-
Mar 24th, 2008, 06:07 AM
#16
Re: How to send E-Mail with VB6
try to set pop authentication on
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 24th, 2008, 06:07 AM
#17
Member
Re: How to send E-Mail with VB6
are you trying with vbsendmail or MAPI component?
Ashish
-
Mar 24th, 2008, 06:08 AM
#18
Member
Re: How to send E-Mail with VB6
you need to provide the authentication to the SMTP server if you have any.
Ashish
-
Mar 24th, 2008, 06:25 AM
#19
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
 Originally Posted by ashishprem
are you trying with vbsendmail or MAPI component?
Ashish
im trying with vbsendmail
This is my code:
Code:
Private Sub Command1_Click()
Set objMessage = CreateObject("CDO.Message")
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.yahoo.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyUserName"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPassword"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.From = "[email protected]"
objMessage.To = "SomeEMailAdress"
objMessage.Subject = "Test1"
objMessage.Textbody = "Hello"
'objMessage.AddAttachment ""
objMessage.Send
End Sub
And I get this error:

Edit:
I dont use any kind of E-Mail software. I have my mail on Yahoo and i access it from my internet explorer.
I have changed this value from 0 to 1 and i get error saying:
Code:
'value i cahanged
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Last edited by Dungeon Keeper; Mar 24th, 2008 at 06:45 AM.
-
Mar 24th, 2008, 06:46 AM
#20
Re: How to send E-Mail with VB6
even if you don't have an email client on your machine you can send smtp email as long as you have an smtp server you can connect to most isp provide a smtp server, but you will need to get the settings for it. the code you are posting in the post above is for cdo message object not vbsendmail, they are dfferent, though proably work much the same underneath. either one needs to connect to smtp server, with the correct settings
vbsendmail comes with good instructions, and examples for use and has setting for pop authentication, which is often used
465 seems a strange port for a smtp server, the default setting is 25
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 24th, 2008, 06:52 AM
#21
Member
Re: How to send E-Mail with VB6
from your code I can see that you trying to connect to yahoo SMTP server. Is it something that you are under yahoo service provider? The SMTP server will be the server details of your internet service provider.
Ashish
-
Mar 24th, 2008, 06:58 AM
#22
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
 Originally Posted by westconn1
even if you don't have an email client on your machine you can send smtp email as long as you have an smtp server you can connect to most isp provide a smtp server, but you will need to get the settings for it. the code you are posting in the post above is for cdo message object not vbsendmail, they are dfferent, though proably work much the same underneath. either one needs to connect to smtp server, with the correct settings
vbsendmail comes with good instructions, and examples for use and has setting for pop authentication, which is often used
465 seems a strange port for a smtp server, the default setting is 25
I found that port setting via google. Ill try to work with vbsendmail now 
I tried with vbsendmail too and i get same error. authentication required
-
Mar 24th, 2008, 07:02 AM
#23
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
 Originally Posted by ashishprem
from your code I can see that you trying to connect to yahoo SMTP server. Is it something that you are under yahoo service provider? The SMTP server will be the server details of your internet service provider.
Ashish
Im not under Yahoo but im trying to send mail via yahoo.
So i cannot send mail via Yahoo if im under diffrent internet provider? I have my email address on Yahoo, i never used E-Mail provided by my provider .
-
Mar 24th, 2008, 07:05 AM
#24
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
Ok, lets start from the beginning.
Ill adjust my mail settings in Outlook. After its done and i can send mail with Outlook what would i need to send mail from VB6.
Would this work?
Code:
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
'Compose new message
MAPIMessages1.Compose
'Address message
MAPIMessages1.RecipDisplayName = "Name"
MAPIMessages1.RecipAddress = [email protected]
' Resolve recipient name
MAPIMessages1.AddressResolveUI = True
MAPIMessages1.ResolveName
'Create the message
MAPIMessages1.MsgSubject = "Subject"
MAPIMessages1.MsgNoteText = "Message text"
'Add attachment
MAPIMessages1.AttachmentPathName = "file path"
'Send the message
MAPIMessages1.Send False
MAPISession1.SignOff
-
Mar 24th, 2008, 07:32 AM
#25
Member
Re: How to send E-Mail with VB6
 Originally Posted by Dungeon Keeper
Im not under Yahoo but im trying to send mail via yahoo.
So i cannot send mail via Yahoo if im under diffrent internet provider? I have my email address on Yahoo, i never used E-Mail provided by my provider  .
no need to use email id provided by service provider.
Once again:
when you execute the vbsendmail application you need to provide the service provider SMTP details. Not of yahoo SMTP.
And it doesn't matter whether your sender is yahoo or any other email server.
You need to provide the authentication if you have any to your SMTP server
-
Mar 24th, 2008, 08:03 AM
#26
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
Oh that, I understand now. Than this can work for me if i am using CDO.message?
-
Mar 24th, 2008, 08:06 AM
#27
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
Doesnt work. i still get same errors.
-
Mar 24th, 2008, 08:23 AM
#28
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
I get an error when trying to add MSMAPI32.OCX saying "name conflicts with existing project, module or object library."
-
Mar 24th, 2008, 04:46 PM
#29
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
Finally I succeeded using MAPI components. Well, i got another question. How is it possible to send to multiple recipients. I dont know, to people from my address book, or to a list of e-mails from a txt document, listbox or something like that.
Is there any way to avoid that annoying Outlook message saying "Program is attempting to send following message on your behalf" with options "Send" and "Do not send".
-
Mar 24th, 2008, 09:19 PM
#30
Re: How to send E-Mail with VB6
Is there any way to avoid that annoying Outlook message saying "Program is attempting to send following message on your behalf" with options "Send" and "Do not send".
do a search, i saw it in a thread at the weekend
you have to use the add method to add recipients, look at the mapi help, i posted some of that in a thread last week
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 25th, 2008, 08:03 AM
#31
Thread Starter
Fanatic Member
Re: How to send E-Mail with VB6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|