-
help nid perfect code for sending email with vb6
can someone tell me what are the codes, objects, and controls to use for sending email with visual basic or can someone tell me where can i download a perfect example application of a visual basic that can send email.
if someone post a code, tell me what is the used of the code and how the code works and what are the things that i should know if i want to create my own vb application that can send email.
thanks in advance!!!!!!!!
sori for my poor english
-
Re: help nid perfect code for sending email with vb6
-
Re: help nid perfect code for sending email with vb6
You can use the ShellExecute function, which uses MS Outlook
VB Code:
Option Explicit
Private 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
Private Const SW_SHOWNORMAL As Long = 1
Private Sub Command1_Click()
ShellExecute Me.hwnd, "Open", "mailto:
[email protected]?Subject=My Email Title Goes Here", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
-
Re: help nid perfect code for sending email with vb6
That actually should use whatever your default mail service is, not just Outlook.
-
Re: help nid perfect code for sending email with vb6
Yes and the one drawback is the limitation of characters in the lpFile argument and adding attachments issue with certain characters. For simple email generation its greeat though.
-
Re: help nid perfect code for sending email with vb6
Quote:
Originally Posted by wiz126
You can use the ShellExecute function, which uses MS Outlook
VB Code:
Option Explicit
Private 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
Private Const SW_SHOWNORMAL As Long = 1
Private Sub Command1_Click()
ShellExecute Me.hwnd, "Open", "mailto:
[email protected]?Subject=My Email Title Goes Here", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
thanks for this example but when i try to run this program ms outlook will open, the code i want is the code which can send e mail without using any other program like ms outlook,
for example
when i click a command button an e-mail message will be send automatically to my emaill add. my question is what are the codes im going to use to the command button so that when i click the command button an email message will be send to my e mail address.
sorry for my poor english!!!
thanks for your replies
thanks in advance !!!!
-
Re: help nid perfect code for sending email with vb6
Search for SMTP on the forums and you will find the code necessary.
-
Re: help nid perfect code for sending email with vb6
The only control you need is the micorosft winsock control, you will find info about this contorl in the network programming section of the vb forums.
So you need to learn how to use winsock to make a connection to a server and send/receive data, then you need to learn the SMTP protocol which is used to send email.
The you can connect to the SMTP server with winsock and use your knowledge of the SMTP protocol to send the mail message.
You will find a lot of info about SMTP on google, the best thing to look for is example sessions, you will learn the protocol very quickly by looking at these.
Note: You will need a mail server to send your emails, i would recommend using your internet service providers mail server, this will put your email address in the from field.
Chris
-
Re: help nid perfect code for sending email with vb6
VB Code:
'Add to references:
'Microsoft CDO for Windows 2000 library
'Microsoft ActiveX Library 2.x
Dim oConfig As CDO.Configuration
Dim oMessage As CDO.Message
Dim oFields As ADODB.Fields
Set oConfig = CreateObject("CDO.Configuration")
Set oFields = oConfig.Fields
With oFields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp.yourServer.com"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "Username"
.Item(cdoSendPassword) = "Password" ' If required
.Update
End With
Set oMessage = CreateObject("CDO.Message")
Set oMessage.Configuration = oConfig
With oMessage
.Subject = "Test mail"
.TextBody = "Test mail"
' .AddAttachment "c:\test.doc"
.Send
End With
-
Re: help nid perfect code for sending email with vb6
thanks for all the reply
Quote:
Originally Posted by oh1mie
VB Code:
'Add to references:
'Microsoft CDO for Windows 2000 library
'Microsoft ActiveX Library 2.x
Dim oConfig As CDO.Configuration
Dim oMessage As CDO.Message
Dim oFields As ADODB.Fields
Set oConfig = CreateObject("CDO.Configuration")
Set oFields = oConfig.Fields
With oFields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp.yourServer.com"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "Username"
.Item(cdoSendPassword) = "Password" ' If required
.Update
End With
Set oMessage = CreateObject("CDO.Message")
Set oMessage.Configuration = oConfig
With oMessage
.Subject = "Test mail"
.TextBody = "Test mail"
' .AddAttachment "c:\test.doc"
.Send
End With
'Microsoft ActiveX Library 2.x ---> why cant i see this in my references and
'Microsoft ActiveX data object Library 2.x---> this are the things i saw in the reference shouk i yse this reference
another thing can i use this code i am using windows xp
sorry for my poor english
-
Re: help nid perfect code for sending email with vb6
Sorry, I meant Microsoft ActiveX data object Library 2.x - shortly "ADO"
No mather if you using XP. You can still use that another library.
-
Re: help nid perfect code for sending email with vb6
sir thanks for the reply, i've tried to use that code but i get an error message
run-time error `2147220975(80040211
The message could not be sent to the SMTP server. The transport error code was 0x80040217. the server response was not available.
and another thing again should i use other control like mapi control or a class module?
i put those code under command button
-
Re: help nid perfect code for sending email with vb6
Quote:
Originally Posted by makmaks
sir thanks for the reply, i've tried to use that code but i get an error message
run-time error `2147220975(80040211
The message could not be sent to the SMTP server. The transport error code was 0x80040217. the server response was not available.
and another thing again should i use other control like mapi control or a class module?
i put those code under command button
What is smtp server on your email count now?
Put same serveraddress here:
VB Code:
.Item(cdoSMTPServer) = "smtp.yourServer.com"
-
Re: help nid perfect code for sending email with vb6
is this correct ?
.Item(cdoSMTPServer) = "smtp.mail.yahoo.com" --> for my yahoo account
.Item(cdoSMTPServer) = "smtp.mail.hotmail.com" --> hotmail
thanks again
-
Re: help nid perfect code for sending email with vb6
Quote:
Originally Posted by makmaks
is this correct ?
.Item(cdoSMTPServer) = "smtp.mail.yahoo.com" --> for my yahoo account
.Item(cdoSMTPServer) = "smtp.mail.hotmail.com" --> hotmail
thanks again
No, try
smtp.yahoo.com or mail.yahoo.com
-
Re: help nid perfect code for sending email with vb6
Hello,
I was looking for this sort of code. So I tried the one given by oh1mie, it is showing runtime error 214722093 (80040213). Should I change any settings in the control panel?
Thank you.
-
Re: help nid perfect code for sending email with vb6
thanks for the reply
sir oh1mie i tried this
smtp.yahoo.com or mail.yahoo.com
but i still get an error message
Run time error 214722093 (80040213).
the transport failed to connect to server
thanks again!!!!
-
Re: help nid perfect code for sending email with vb6
The issue may be that you dont have CDO 1.21 installed on your system. It is installed as an optional item when installing Outlook.
-
Re: help nid perfect code for sending email with vb6
Every country have own rules.
Here we use allways ISP's smtp server.
You probably have cdo, if you did find it to the references
-
Re: help nid perfect code for sending email with vb6
Quote:
Originally Posted by oh1mie
Every country have own rules.
Here we use allways ISP's smtp server.
You probably have cdo, if you did find it to the references
Your country has a law against interacting with an SMTP server other than your Internet Service Provider? I must look that one up...thats like the law in USA where you can't keep a horse in your bathtub..lol - not that i do that :D
-
Re: help nid perfect code for sending email with vb6
More then likely youll have to authenticate so you will need an account. This in turn will limit your use or prohibit it since companies like yahoo dont let you use their servers for anything other the "normal" use.
-
Re: help nid perfect code for sending email with vb6
Quote:
Originally Posted by the182guy
Your country has a law against interacting with an SMTP server other than your Internet Service Provider? I must look that one up...thats like the law in USA where you can't keep a horse in your bathtub..lol - not that i do that :D
I have my own exchange smtp server, but for this practice is perhaps reason spam and virus writers. It's not a law.
-
Re: help nid perfect code for sending email with vb6
Quote:
Originally Posted by RobDog888
The issue may be that you dont have CDO 1.21 installed on your system. It is installed as an optional item when installing Outlook.
why would it become an issue
actually i have cdo 1.21 installed in mine
thanks again for all your post
-
Re: help nid perfect code for sending email with vb6
I didnt know if you had it or no, but since you do then its not an isue.
-
Re: help nid perfect code for sending email with vb6
Quote:
Originally Posted by RobDog888
I didnt know if you had it or no, but since you do then its not an isue.
ah ok
thanks for the reply
i thought i nid the cdo 1.21 control to run the program
thanks again for all the reply!!!
-
Re: help nid perfect code for sending email with vb6
You need it for the code example in post #9 but you can also just use pure SMTP but you need access to a SMTP server.
-
Re: help nid perfect code for sending email with vb6
sorry for the double reply but pls can you edit this for me
visual basic code:-------------------------------------------------------------------------------- 'Add to references:
'Microsoft CDO for Windows 2000 library
'Microsoft ActiveX Library 2.x
Dim oConfig As CDO.Configuration
Dim oMessage As CDO.Message
Dim oFields As ADODB.Fields
Set oConfig = CreateObject("CDO.Configuration")
Set oFields = oConfig.Fields
With oFields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp.yourServer.com" ---->example of this in hotmail cause i cant do it with yahoo
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "Username" --->is this the username of ".from"
.Item(cdoSendPassword) = "Password" ' If required ---->
.Update
End With
Set oMessage = CreateObject("CDO.Message")
Set oMessage.Configuration = oConfig
With oMessage
.To = "[email protected]"
.From = "[email protected]" are this example is correct
.Subject = "Test mail"
.TextBody = "Test mail"
' .AddAttachment "c:\test.doc"
.Send
End With
thanks again !!!!
sorry for my poor english
-
Re: help nid perfect code for sending email with vb6
You can edit your own posts. ;) Add the [vbcode] tags and it will format it.
The user name is the account username that you should have that gives you access to your email account, but usually they dont let you use their servers to send out much mail for anything other then personal connunications, etc..
-
Re: help nid perfect code for sending email with vb6
ah ok thanks so iis that means that i cannot use yahoo or hotmail for this and i should search another server that can let me any email message i want?
thank you veru much for all the reply!!!!
sorry for my poor english
-
Re: help nid perfect code for sending email with vb6
Yes, that is correct. Most ISPs have stuff in place to prevent their servers from being used for mail nodes since it can be used to send out tons of spam and place ridicules amounts of load on their servers.
-
Re: help nid perfect code for sending email with vb6
can i use this so called QK SMTP Server
QK SMTP Server is a powerful but extremely easy-to-use smtp server software, which can send mails from local host to the recipients' mailboxes directly at an amazingly high speed. Arrived or not, you will get feedback instantly.
can i use that as a smtp server to send email using visual basic
thanks!!!
sorry for my poor english