Link to home
Create AccountLog in
Avatar of Cristi_E
Cristi_EFlag for Romania

asked on

Send Email VB6

Hy experts,
    I need to develop a Visual Basic 6 application that will send me an email in certain circumstances.
  Do you have any ideeas on what is the most convenient way to accomplish that?
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

the easiest and safest way to send e-mails with VB6 is to use the free http://www.freevbcode.com/ShowCode.Asp?ID=109
Avatar of Cristi_E

ASKER

Can i use winsock?
You could but I don't have a safe link to give you.
Can you give me a vbSendMail.dll example that uses Yahoo or GMail ? Can i use it for these two sites?
There are code examples when you download it. I never used it for those sites. Usually, it is the same as any other e-mail provider except the port that you have to use (which is often 465 or 587).
Avatar of Antagony1960
Antagony1960

Unfortunately, vbSendMail doesn't work using Gmail or Yahoo account settings for sending. This is because they both use SSL, which vbSendMail doesn't support.

The only way I've been able to send emails using SSL accounts in VB6 is by using the Microsoft CDO object, which relies on Outlook being installed, configured (for the SMPT server) and running on the client machines. Personally, I prefer to use vbSendMail using a non-SSL SMTP server account--most normal ISPs don't use SSL--as the only thing you need to be sure the client machines have are the VB6 runtimes and MSWINSCK.OCX registered.
>>This is because they both use SSL, which vbSendMail doesn't support.

I wasn't aware of that .

Maybe have a look at http://www.vbforums.com/showthread.php?t=517734
good morning!


try this approach!


sub SendEmail()
    Dim objMsg As Object
    Dim objConfi As Object
    Dim strBody As String
   
    Set objMsg = CreateObject("CDO.Message")
    Set objConfi = CreateObject("CDO.Configuration")
   
    With objMsg
        Set .configuration = objConfi
        .to = <receiver>
        .from = <sender>
        .Subject = "Test"
        .textbody = "This is a test message only."
        .AddAttachment <path of the file to attached>     ' example "C:\test.txt"
        .send
    End With
   
    MsgBox "OK"
end sub


i hope i could give u idea...

game-master
ASKER CERTIFIED SOLUTION
Avatar of game-master
game-master
Flag of Philippines image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Simply setting the CDO's From, To, Subject and Body elements isn't enough for SSL accounts like those specified by the author Cristi_E (GMail or Yahoo). For those types of accounts you have to specify the configuration details before defining the basic elements.

Oh, and there is another problem with CDO for W2K... for some reason it doesn't seem to work on SSL accounts in conjunction with Outlook 2007!

Anyway, here is an example of the CDO code I managed to send an email with using a Yahoo account and from a machine with Outlook 2003 on it:
Dim cdoCfg As New CDO.Configuration
Dim cdoMsg As New CDO.Message
 
    cdoCfg.Load cdoDefaults
 
    With cdoCfg.Fields
        !cdoSMTPUseSSL = True
        !cdoSMTPAuthenticate = cdoBasic
        !cdoSendUserName = mySSL_Account_UserName
        !cdoSendPassword = mySSL_Account_Password
        !cdoSMTPServer = mySSL_SMTP_Server
        !cdoSendUsingMethod = cdoSendUsingPort
        !cdoSMTPServerPort = 465
        !cdoSMTPConnectionTimeout = 100
        .Update
    End With
        
    With cdoMsg
        Set .Configuration = cdoCfg
        .From = "please_pay@ention.com"
        .To = "hey_you@theback.com"
        .Subject = "CDO SSL Test"
        .TextBody = "This is a test of CDO mail"
        .Send
    End With
    Set cdoMsg = Nothing
    Set cdoCfg = Nothing

Open in new window


Thank you for your posts,  Antagony1960!    Somehow i can't succceed with your code. The only moddifications i made were:
    mySSL_Account_UserName = "myemailadress"     'without   '@yahoo.com'
    mySSL_Account_Password = "myemailpassword"
    mySSL_SMTP_Server = "smtp.yahoo.com"

    What did i missed?   I have Outlook 2002 installed on my computer.
   It turns me no error.....  but the message never arrives....to gmail   or even my yahoo adress...
    Thanks!
 
Do you also have your Outlook configured for your Yahoo account? If you can send emails from Outlook with the Yahoo account, I would have thought you should be able to get the code to work.

On mine I found had use my full email address for the UserName and I'm not sure whether your mail server setting is correct; my Yahoo account is a .uk domain and the mail server is set to "smtp.mail.yahoo.co.uk" - I would have thought standard Yahoo accounts would have the same setting but with .com  on the end.


good morning!

my posted snippets works fine...
i hope u tried it to...


game-master
Hello game-master
     I have tryed you code but no luck.   If you can send me a example working project on yahoo or gmail would be verry helpfull!

   Thanks!
@Crist_E:

Where are you based? Only I thought I'd try to find out what Yahoo's SMTP server is and I noticed they're saying that POP mail is now only available for Mail Plus accounts. According to this Wikipedia article their free accounts only allow POP in certain countries (not the US).
I have a simple (free) Yahoo! Mail account, and i can't access it with Outlook Express 6.  But i think that i should be able to send mail on behalf of that account
I'm not even sure that CDO will work with Outlook Express. All I know is it works on my old XP machine with Outlook 2003, but Outlook has to be both configured for the account and running or it fails.

If the reason it doesn't work for you is because of Yahoo's POP policy, I've heard that it's possible to get around that by logging on to your account and changing your location to Asia. Another one I've heard is that it's possible to use the settings used for iPhones; i.e smtp.mobile.mail.yahoo.com on port 25. Both might be worth a try.
good morning!

try this...

goto PROJECT>REFERENCES>MICROSOFT CDO FOR WINDOWS 2000 LIBRARY


use this code...

sub sendEmail()
   Dim objCDO As New CDO.Message
   
    With objCDO
         .Subject = "Test"
         .From = "alvindoliente@yahoo.com"
         .To = "addoliente@findme.com.ph"
         .TextBody = "Hello alvin... this is a test message."
         .Send
    End With
end sub

i hope this will give u idea...


*** this codes works fine with me and I'm using this on my program...
are your sure this code doesnt work with you?


game-master
Hello game-master
    I have used your code now exactly as it is with no modifications. Instead of linking MICROSOFT CDO FOR WINDOWS 2000 LIBRARY (CDOSYS) (it is not available on my VB6) i've linked MICROSOFT CDO FOR EXCHANGE 2000 LIBRARY(CDOEX). But i've searched the net and found this article http://support.microsoft.com/kb/318823 that says "CDOEX is a superset of CDOSYS. This means that CDOEX contains all of the functionality of CDOSYS, plus additional functionality for use with Microsoft Exchange Server 2000" ... so it should be no problem.
   I have also found this threat: http://www.webhostingtalk.com/showthread.php?t=505770
  Unfortunatelly i can't make it work.
   
This is a screen-shot with the error.
Error-80040211.bmp
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thank you verry much for your support. I really appreciate it!