Click to See Complete Forum and Search --> : How can I send automatic e-mails with VB6?
janogueira
Oct 27th, 2000, 06:11 AM
I want to send e-mails from my routines in VB6 but I don't know how without need to be there to press SEND button.
How can I do this with Eudora or any kind of e-mail program?
You might try the ShellExecute API call. It causes the OS to launch appropriate programs based on file types/extensions.
In a regular .BAS module declare the function:
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
And in your code use something like:
Dim lngResult
lngResult = ShellExecute(Me.hwnd, "Open", "mailto:someone@somedomain.com", "", "", vbNormalFocus)
This would cause your browsers default email client to open up a new message addressed to someone@somedomain.com.
If you wanted email to automatically be sent from your application (without user intervention) you'd likely need an object library for the software you wanted to send with, like using the Outlook Object Library for sending via Outlook/Exchange.
Good luck,
Paul
ccoder
Oct 27th, 2000, 10:37 AM
You can easily send a message by declaring Outlook objects. You will have to determine what/when to send. You did not indicate why you want to send an email to someone.
Do you want to notify someone when a particular event occurs? Do you want to send out regulary scheduled messages? If so, just call a procedure to send the email when the event does occur. I am doing that now with a process monitor interface. Using Outlook, I send text pages to the appropriate people when there is an event that needs immediate attention.
Try something like this:
Private Sub Auto_Send()
Dim objOutlook As New Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
'Create new message
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
' Set all desired Outlook properties
With objOutlookMsg
.To = "userid@users_address"
.Subject = "Automated email test"
.Body = "This is line 1" & vbNewLine
.Body = .Body & "This is line 2" & vbNewLine
.Importance = olImportanceHigh
.Send
End With
Set objOutlookMsg = Nothing
'Close Outlook instance: Important!
Set objOutlook = Nothing
MsgBox "Auto Email Complete", vbInformation
End Sub
janogueira
Oct 30th, 2000, 04:26 AM
PWNettle as sent me an interesting code. It results but I have to little observations:
1. I can't post the Subject into the e-mails
2. It only has utility for me if it would send my e-mail automaticly because I'm not in there to click the SEND Button.
I use Eudora or Microsoft Outlook. Who can help me? I will change my e-mail browser if someone knows how to do so with another one.
My best regards
José Nogueira - PORTUGAL
Um, use ccoder's example of how to use Outlook.
Paul
oetje
Oct 30th, 2000, 09:22 AM
I think the best way to send emails is by using winsock. http://www.vbsquare.com/articles/sendmail/
janogueira
Nov 6th, 2000, 04:41 AM
I'm trying the OETJE code but I can't found the Mswinsck.ocx file in my machine.
So, my VB6 compiler doesn't compile and link it.
Who can send me this missing file?
My best regards
José Nogueira
janogueira
Nov 6th, 2000, 03:01 PM
The code suggested by OETJE really works. It the most useful code I ever seen since I programm in VB6.
My best regards for OETJE and for this Forum
José Nogueira
janogueira
Nov 7th, 2000, 11:54 AM
I tried the code OETJE noticed and it works.
However, it had not worked initialy because I had not checked the Winsock component in the object bar.
After doing that I finally compiled and linked this code.
To soon for a party...
The prelinked exe file already works, the vbp file is compilable and linkable but after that it doesn't work because it answers me "Run-time error '13': type mysmatch!". I try to do a Step by Step running and this error is concerned with the code line "ConnectToServer txtServer.Text, Winsock1", where it stops. However, sometimes my VB6 doesn't compile and tells me "Compile error: variable not defined!" pointing to "Winsock1" code of line "ConnectToServer txtServer.Text, Winsock1", the same of the last problem.
WHO CAN HELP MEEEEEEE? I'm one little step from my objective.
My best regards
José Nogueira
janogueira
Nov 7th, 2000, 03:21 PM
Please, don't forget me. Who can help me?
José Nogueira
toto_phl
Sep 12th, 2007, 04:09 AM
hi,
kinda new hir...
i tried the ccoder's code, i encounter an error,
"A program is trying to automatically send email on your behalf.
Do you want to allow this?
If this is unexpected, it may be a virus and you should choose 'No'.
buttons <Yes> <No> <Help>"
can it be automatically? i mean i think it should not prompt like that...
thanks,
toto
ccoder
Sep 12th, 2007, 07:59 AM
That is due to some security changes that Microsoft implemented several years ago.
You may want to consider using SMTP. Take a look at the code that I posted here (http://www.vbforums.com/showthread.php?t=323723).
westconn1
Sep 13th, 2007, 07:19 AM
@ccoder
i downloaded your sample from the link above, but i need to find out how to put recipient & sender address and subject, you done any of that?
ok i just found the code for that, was looking in the wrong place
toto_phl
Sep 14th, 2007, 01:57 AM
i tried the link that you provided...
but was not successfull in running the code, i've encountered an error stating:
"Run-time error '40006':
Wrong protocol or connection state for the requested transaction or request"
why is it like that?
but i can send email using OUTLOOK, using the same SMTP host name...
please help...
tommygrayson
Sep 14th, 2007, 02:12 AM
Use Microsoft CDO. It will not prompt a messagebox if you are sending e-mails.
:thumb:
toto_phl
Sep 14th, 2007, 02:21 AM
hey tommy,
can you spare some codes with it?
thanks
tommygrayson
Sep 14th, 2007, 03:02 AM
hey tommy,
can you spare some codes with it?
thanks
Have you already included the Microsoft CDO Library in your Library?
If so then hmmm........
Let me seeee........
Dang. It has been a long time since I programmed with VB 6 that I almost forgot to use CDO in VB6.
Anyway, click on this link (http://www.vbforums.com/showthread.php?t=487335&highlight=CDO)
westconn1
Sep 14th, 2007, 03:23 AM
i was using cdo to send faxes previously, but i started getting security notification issues with it, so went to using other methods
for all you ever wanted to know about cdo, try http://www.cdolive.com/default.htm
toto_phl
Sep 14th, 2007, 03:24 AM
i already added CDO in the reference...
got the source code from the link you provided...
but the part where it states the:
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
it said that it should use the IP address, i dunno the IP. i only know the host name...
is it the same?
:sick:
westconn1
Sep 14th, 2007, 03:28 AM
Run-time error '40006':
Wrong protocol or connection state for the requested transaction or request"
this can be resolved by changing the sever address to an ip address
to get the ip address, you can ping the server address or with winsock as after connecting the connection ip address is one of its properties
toto_phl
Sep 14th, 2007, 03:35 AM
what if you don't know the IP address, only the host name?
is it the same?
tommygrayson
Sep 14th, 2007, 05:08 AM
what if you don't know the IP address, only the host name?
is it the same?
You can determine the IP address of the host name by pinging it.
You can also type the Host name instead of the IP name but it is not common practice.
westconn1
Sep 14th, 2007, 08:17 AM
i believe winsock needs to resolve the server address to a MX server to send mail, so if the server (hostname) you connect to is an A or other server it will fail to send mail, with the error you reported before, if you connect to the ip address of the server it will look at what servers are available, at that IP, to see if there is a MX server to connect to
ccoder
Sep 14th, 2007, 08:28 AM
i tried the link that you provided...
but was not successfull in running the code, i've encountered an error stating:
"Run-time error '40006':
Wrong protocol or connection state for the requested transaction or request"
why is it like that?
but i can send email using OUTLOOK, using the same SMTP host name...
please help...
I can't help you until I get some more information.
Did you make any changes other than filling in the 3 pieces of information that the program needs? These would be in the lines:
sckMail.RemoteHost = "smtp server address goes here" ' supply server address
addyList = "address1@domain1;address1@domain2" ' supply address list (1 or more)
sckMail.SendData "MAIL FROM:<sender@domain>" & vbCrLf ' supply sender@domain
Where in the code is the error occurring? What have you done up to that point?
westconn1
Sep 14th, 2007, 05:06 PM
@ ccoder, i got the same error when i put our server address in the format www.????????.com.au (as it is in outlook etc)
when i put it in as an IP address it worked ok, (see my post above) as it resolved to the mail server
but the test emails i sent mostly did not arrive (out of about 10 sent to 2 email addresses only 1 arrived) so i have to look at it some more
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.