-
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 :D.
-
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
-
Re: How to send E-Mail with VB6
Quote:
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?
-
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..
-
Re: How to send E-Mail with VB6
you need to assign the outlook profile name in the code
-
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/
-
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
-
Re: How to send E-Mail with VB6
i will go with westconn. vbsendmail is the best.
-
Re: How to send E-Mail with VB6
Thanks guys. Ill try it now :D
-
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?
-
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
-
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
-
Re: How to send E-Mail with VB6
-
Re: How to send E-Mail with VB6
I get an error saying:
Quote:
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
-
Re: How to send E-Mail with VB6
I fixed that but now i get "530 Authentication required"
-
Re: How to send E-Mail with VB6
try to set pop authentication on
-
Re: How to send E-Mail with VB6
are you trying with vbsendmail or MAPI component?
Ashish
-
Re: How to send E-Mail with VB6
you need to provide the authentication to the SMTP server if you have any.
Ashish
-
Re: How to send E-Mail with VB6
Quote:
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:
http://img233.imageshack.us/img233/6067/errgu7.gif
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
http://img329.imageshack.us/img329/2285/errrx2.gif
-
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
-
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
-
Re: How to send E-Mail with VB6
Quote:
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 :D
I tried with vbsendmail too and i get same error. authentication required :(
-
Re: How to send E-Mail with VB6
Quote:
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 :(.
-
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
-
Re: How to send E-Mail with VB6
Quote:
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
-
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?
-
Re: How to send E-Mail with VB6
Doesnt work. i still get same errors.
-
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."
-
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".
-
Re: How to send E-Mail with VB6
Quote:
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
-
Re: How to send E-Mail with VB6