Easiest way to send simple email from VB6?

I want to find a simple way to send emails from within a VB 6 applkication.

I have been unsuccessful in using MAPI (see code below) possibly due to my not being familiar with the MAPI commands and that I do not have MS Outlook or Outlook Express installed on my computer.  Here is what I have tried:

Option Explicit

Private Sub Form_Load()
    MAPISession1.SignOn
    MAPISession1.NewSession = True
    MAPIMessages1.SessionID = MAPISession1.SessionID
End Sub

Private Sub cmdSend_Click()
    MAPIMessages1.MsgIndex = -1
    MAPIMessages1.RecipAddress = "JohnDoe@earthlink.net"
    MAPIMessages1.MsgSubject = "Subject line of this email"
    MAPIMessages1.MsgNoteText = "Text of this email"
    MAPIMessages1.Send False
End Sub

Private Sub cmdExit_Click()
    MAPISession1.SignOff
    Unload Me
End Sub

When I run the above app, I get this message:  "Microsoft Office Outlook"  "No profiles have been created.  To create a new profile, use the Mail icon in the Control Panel."

After clicking the "OK" button on the error message, I get a MS VB Run-time error '32003': Login has failed" on the "MAPISession1.SignOn" line.

I would prefer to not install Outlook on my computer as I use a web email service.  Is there any way around this or another way in VB 6 so send emails?

Thanks for the help.
LVL 7
EYoungAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteveH_UKCommented:
Try using the CDO library for sending mail using an SMTP server.  MAPI requires a mail profile and is typically used with an enterprise mail system.

Have a look at this article: http://www.asp101.com/articles/john/cdosmtprelay/default.asp
0
DamionasCommented:
Try this,

This project was originally developed by FreeVBCode.com, but Dean Dusenbery has taken ownership of it since version 2.0. He has done numerous version upgrades since that time. These upgrades represent a major improvement to the previous version. Thanks to Dean, the component is clearly of commericial quality, and probably one of the best available, commericial or non-commerical. FreeVBCode.com, along with all users of this component extend their eternal gratitude.
If you've ever wanted to send simple e-mail messages with Visual Basic, and you've tried struggling with third party .OCXs or Microsoft's unwieldy MAPI or CDO libraries, the vbSendMail.dll is for you. This simple to use component supports multiple file attachments and multiple copies of the same e-mail.

Sending an e-mail with this .dll is as simple as the following:


'Module Level Declaration (WithEvents optional but recommended)
Private WithEvents poSendMail as vbSendMail.clsSendMail
Private Sub cmdSend_Click()
'Assumes you have a form with text boxes named as below

set poSendMail = new vbSendMail.clsSendMail
poSendMail.SMTPHost = txtServer.Text
poSendMail.From = txtFrom.Text
poSendMail.FromDisplayName = txtFromName.Text
poSendMail.Recipient = txtTo.Text
poSendMail.RecipientDisplayName = txtToName.Text
poSendMail.ReplyToAddress = txtFrom.Text
poSendMail.Subject = txtSubject.Text
poSendMail.Attachment = txtFileName.text 'attached file name
poSendMail.Message = txtMsg.Text
poSendMail.Send
set poSendMail = nothing
End Sub

For multiple file attachments, an example would be:

poSendMail.Attachment = txtFileName1.text & ";" & txtFileName2.text

Note that this is only a small example of the component's capabilities and options, and you can use it for simple purposes, as described above, or use any number of its advanced features, as described in the documentation.

Two sample clients with .vbgs and detailed documentation can be found at the following url:

http://www.freevbcode.com/code/vbSendMail.zip
0
EYoungAuthor Commented:
SteveH_UK: thanks.  I need to leave the office and will not be back until tomorrow or the next day.  Can you provide some VB 6 code sample so I can see how it works?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

SteveH_UKCommented:
There's a full example in the link (scroll down!).  Did you see that?
0
EYoungAuthor Commented:
SteveH_UK:  Yes, I see it.  I feel uncomfortable hard coding in HTTP links to MS web sites.  If those links change in the future, won't the program abend with a broken link?
0
Chris BottomleySoftware Quality Lead EngineerCommented:
A common reference for CDO would be:

http://www.rondebruin.nl/cdo.htm

As long as you have a mail account and password to use then using the example .. simply replace details as appropriate.

Chris
Sub CDO_Mail_Small_Text()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Variant
 
  Set iMsg = CreateObject("CDO.Message")
  Set iConf = CreateObject("CDO.Configuration")
 
  iConf.Load -1    ' CDO Source Defaults
  Set Flds = iConf.Fields
  With Flds
   .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
   .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
     = "Fill in your SMTP server here"
   .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
   .Update
 End With
 
    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"
 
    With iMsg
        Set .Configuration = iConf
        .To = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .From = """Ron"" <ron@something.nl>"
        .Subject = "Important message"
        .TextBody = strbody
        .Send
    End With
 
End Sub

Open in new window

0
SteveH_UKCommented:
The links are just names for schemas.  No access is made of websites, and no the links aren't likely to change in any case.  Microsoft uses them to indicate the 'schema' of the settings only.  It's a way of configuring a property by a unique name, but it is ugly!
0
DamionasCommented:
EYoung: I don't like hardcoding links into code either, which is why I recommend using the DLL I suggested above, works very well for most purposes.
0
EYoungAuthor Commented:
Thank you both for the input.  I am not sure which to use.  The client's needs are pretty simple.  I think they are using Windows and may or may not use MS Outlook or Express.  I want the fewest dialog boxes popping up on the screen when the client sends the emails.  Ideally the client would just click the send button and an email would be sent without any messages or further actions required.

Can either of the above two suggestions do that?

I will be out today but returning tonight.  Thank you both for your help and patience.

Regards,
EYoung
0
Chris BottomleySoftware Quality Lead EngineerCommented:
That's exactly what my post does, no user interaction once the macro is inserted with an appropriate mail server and constants etc.

Chris
0
SteveH_UKCommented:
My solution also does that and the library is shipped as part of Windows.
0
SteveH_UKCommented:
chris_bottomley: your solution is the same as the one I offered, i.e. it uses CDO and has a complete example.  I don't dispute your solution, I just think it is identical.
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Can't dispute the basic statement, but my post refers to an explicit VBA example as was identified by the zone.  If the EYoung is happy with that then I have no problem.

Chris
0
SteveH_UKCommented:
Chris: VBScript code works in VBA without alteration.  Anyway, no problem with me.  I just wanted to ensure clarity.  Thanks.
0
DamionasCommented:
I like the solution I suggested as it is independent of microsoft and support is available for future enhancements. While you may want to just use it for basic email write now, both solutions provide that. However in the future, your client may want some of the more advanced functions, which would also be available in the DLL solution.

Good luck
0
EYoungAuthor Commented:
I am having problems getting this code to run.  The first problem is with the word "Server" in the third line down in the cmdSend_Click() private sub.  Attached is the code.  Would appreciate any help to see if this will work.  Thank you.


Option Explicit
 
Private Sub Form_Load()
    Const cdoSendUsingMethod = _
        "http://schemas.microsoft.com/cdo/configuration/sendusing"
    Const cdoSendUsingPort = 2
    Const cdoSMTPServer = _
        "http://schemas.microsoft.com/cdo/configuration/smtpserver"
    Const cdoSMTPServerPort = _
        "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
    Const cdoSMTPConnectionTimeout = _
        "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
    Const cdoSMTPAuthenticate = _
        "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
    Const cdoBasic = 1
    Const cdoSendUserName = _
        "http://schemas.microsoft.com/cdo/configuration/sendusername"
    Const cdoSendPassword = _
        "http://schemas.microsoft.com/cdo/configuration/sendpassword"
    
    Dim objConfig  ' As CDO.Configuration
    Dim objMessage ' As CDO.Message
    Dim Fields     ' As ADODB.Fields
End Sub
 
Private Sub cmdSend_Click()
    ' Get a handle on the config object and it's fields
    Set objConfig = Server.CreateObject("CDO.Configuration")
    Set Fields = objConfig.Fields
    
    ' Set config fields we care about
    With Fields
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = "mail.company.com"
        .Item(cdoSMTPServerPort) = 25
        .Item(cdoSMTPConnectionTimeout) = 10
        .Item(cdoSMTPAuthenticate) = cdoBasic
        .Item(cdoSendUserName) = "EYoung"
        .Item(cdoSendPassword) = "xyz"
    
        .Update
    End With
    
    Set objMessage = Server.CreateObject("CDO.Message")
    
    Set objMessage.Configuration = objConfig
    
    With objMessage
        .To = "Display Name <email_address>"
        .From = "Display Name <email_address>"
        .Subject = "SMTP Relay Test"
        .TextBody = "SMTP Relay Test Sent @ " & Now()
        .Send
    End With
End Sub
 
Private Sub cmdExit_Click()
    Set Fields = Nothing
    Set objMessage = Nothing
    Set objConfig = Nothing
    
    Unload Me
End Sub

Open in new window

0
EYoungAuthor Commented:
Also, if the above code does not work, then can someone supply a simple code example that just sends an email?  Thanks
0
SteveH_UKCommented:
You can't use the Server object because you are not running on a web page, however you don't need to as you can use CreateObject directly.  See attached.

Note also that the constant declarations and the variables need to be at the module level, not just in the Form_Load method, otherwise they are inaccessible to the other methods.

Since you are using VB, you also have the option of adding references to the Microsoft CDO and ADO libraries which will give you typed support from within VB.

To do this, add a project reference from within VB.  The CDO library is implemented by %systemroot%\system32\cdosys.dll.  It will be named "Microsoft CDO for Windows 2000 Library".  The ADO library is implemented by C:\program files\common files\system\ado\msado15.dll.  It will be named similar to "Microsoft ActiveX Data Objects 2.5 Library".  The version may differ (for example 2.6, 2.7, 2.8, ...).
Option Explicit
 
    Const cdoSendUsingMethod = _
        "http://schemas.microsoft.com/cdo/configuration/sendusing"
    Const cdoSendUsingPort = 2
    Const cdoSMTPServer = _
        "http://schemas.microsoft.com/cdo/configuration/smtpserver"
    Const cdoSMTPServerPort = _
        "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
    Const cdoSMTPConnectionTimeout = _
        "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
    Const cdoSMTPAuthenticate = _
        "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
    Const cdoBasic = 1
    Const cdoSendUserName = _
        "http://schemas.microsoft.com/cdo/configuration/sendusername"
    Const cdoSendPassword = _
        "http://schemas.microsoft.com/cdo/configuration/sendpassword"
    
    Dim objConfig  ' As CDO.Configuration
    Dim objMessage ' As CDO.Message
    Dim Fields     ' As ADODB.Fields
 
 
Private Sub Form_Load()
End Sub
 
Private Sub cmdSend_Click()
    ' Get a handle on the config object and it's fields
    Set objConfig = CreateObject("CDO.Configuration")
    Set Fields = objConfig.Fields
    
    ' Set config fields we care about
    With Fields
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = "mail.company.com"
        .Item(cdoSMTPServerPort) = 25
        .Item(cdoSMTPConnectionTimeout) = 10
        .Item(cdoSMTPAuthenticate) = cdoBasic
        .Item(cdoSendUserName) = "EYoung"
        .Item(cdoSendPassword) = "xyz"
    
        .Update
    End With
    
    Set objMessage = CreateObject("CDO.Message")
    
    Set objMessage.Configuration = objConfig
    
    With objMessage
        .To = "Display Name <email_address>"
        .From = "Display Name <email_address>"
        .Subject = "SMTP Relay Test"
        .TextBody = "SMTP Relay Test Sent @ " & Now()
        .Send
    End With
End Sub
 
Private Sub cmdExit_Click()
    Set Fields = Nothing
    Set objMessage = Nothing
    Set objConfig = Nothing
    
    Unload Me
End Sub

Open in new window

0
EYoungAuthor Commented:
SteveH_UK:

Your code example really helped.  The program now runs and gets most of the way through but gets a Run-time error at the .Send line.  The error message is "The transport failed to connect to the server."

I did make the changes you suggested.  It sounds like the program is not successfully connecting (authenticating) with the SMTP server.  What do you think?

I increased the points to 200.  Thank you for the extra effort.

EYoung
0
SteveH_UKCommented:
First off, I'd try connecting from your machine using telnet as I think the problem is a networking/SMTP configuration one, not a programming one per se.

Open a command prompt and try:

telnet mail.company.com 25

This should connect you.  If it does then authentication is the problem.  If you can't connect because the server refused the connection then either SMTP is not running at the address or it is configured to deny connections from your computer.  If it can't connect at all then you need to check the address 'mail.company.com'.

Let me know how you get on with that.
0
DamionasCommented:
You wouldn't be having all these headaches if you just used the DLL i provided :) But don't listen to me, listen to the "Experts"
0
EYoungAuthor Commented:
I understand your point Damionas and it is a good one.  I just want to try to do this without using third party software.  If I can't do this with CDO, then I will, indeed, use your suggestion.  Thank you for hanging in with me while I try the other approach.

SteveH UK - I just typed this at the command line:  telnet mail.haciendadata.com 25  and it gives me a connection failure error.  I think you are right that it may be an authentication error.  I have written an email to my contact there and should hear back later.  Will be out of the office again today until 10 pm tonight (California time).  It is 9 am now.  Thanks for the help.
0
SteveH_UKCommented:
If you can't connect it won't be a normal authentication error.  The reason is that authentication with SMTP normally happens later when the authentication commands are issued.  This sounds like you are blocked access to the SMTP server.  At this point, using a 3rd party system offers no advantage, after all you can't even connect with telnet.

Check to see whether the administrator of the SMTP server requires a different port, IP address or has restrictions on what computers can connect.  This is the first line of enquiry.

Secondly, try a PING command:

ping mail.company.com

This will tell you if DNS is at fault.  You'll know it's a DNS error if it can't find an IP address.
0
EYoungAuthor Commented:
SteveH UK:  It looks like the problem may be a firewall problem at me end.  When I remote into another client's computer, I can successfully execute the telnet command.  But when I type the same command from my computer, I get the connect failure.  I am trying to shut down the firewalls and anti-virus software on my computer and will try again.  Will keep you posted.  Thanks for hanging in here with me.
0
EYoungAuthor Commented:
Shutting down the firewall and anti-virus at my end did not work.  Still getting the same connect failure msg.

When I issue the telnet command, how do I know it worked successfully?  From my computer I get a connect failure.  When I remote into another client's computer, I do not get a connect failure error message.  It just looks like it is waiting for me to type in some type of command.  What does a successful connect look like?

I also tried running the VB6 application from the remote client's computer and I got the same transport error.

Thanks
0
EYoungAuthor Commented:
Also, I tried the ping command from my computer.  It just generates four "Request timed out" messages.  When I try the ping from the remote client's computer I also get the four timed out messages which is odd because I can successfully issue the telnet command from the remote client's computer.  Not sure what is going on.  Any ideas?  Thanks
0
DamionasCommented:
Just some thoughts, the following works with the DLL, but may work with the CDO as well

If you are experiencing problems getting your SMTP server to send mail, here are a few things to check:

Relaying / Transfer Mode  Make sure inbound/outbound transfer is enabled for all hosts.

Accept Connections  Make sure there are no restrictions on SMTP connections.

Client Authentication -  Make sure the server allows your client to connect via a supported authentication mode or turn off authentication.

Mail Routing  Verify SMTP & POP3 routing configuration.

Routing Restrictions  Make sure there are no SMTP, POP3 or host routing restrictions and that anything required for SMTP/POP3 is enabled.

 I would not recommend using your fully qualfied domain name, as some routers will route this outside of your network and back in, even though this is not standard.  I would look for a local server, like your exchange server that has the smtp port open, most likely you can use this to relay your messages. If not, ask your exchange admin to open it.

Or if you have the ability to use a socks proxy, You can try this third party solution, see link:
http://www.emailarchitect.net/easendmail/

I provided a code example on how the proxy settings would work.


Imports EASendMail
Sub SendMail()
    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    Dim oSmtp As SmtpClient = New SmtpClient
 
    Try
        Dim oServer As SmtpServer = New SmtpServer("smtp.adminsystem.com")
        
        oServer.SocksProxyServer = "192.168.0.1"
        oServer.SocksProxyPort = 1080
        ' if your proxy doesn't requires user authentication, please don't assign any value to 
        ' SocksProxyUser and SocksProxyPassword properties 
        oServer.SocksProxyUser = "tester"
        oServer.SocksProxyPassword = "pass"
        oServer.ProxyProtocol = SocksProxyProtocol.Socks5 
            
        
        'set user authentication
        'oServer.UserName = "myuser@adminsystem.com"
        'oServer.Password = "mypassword"
        
        'specifies the authentication mechanism.
        'oSmtp.AuthType = SmtpAuthType.AuthAuto
        
        'set SSL connection
        'oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
        
        'set smtp server port
        'oServer.Port = 465
        
        'set helo domain
        'oServer.HeloDomain = "mymachine.com"
        
        'set delivery-report address
        'oServer.MailFrom = "report@adminsystem.com"
        
        
        oMail.From = New MailAddress("from@adminsystem.com")
        oMail.To.Add(New MailAddress("to@adminsystem.com"))
        
        oMail.Subject = "test subject"
        oMail.TextBody = "test body"
                       
        oSmtp.SendMail( oServer, oMail )
        Console.WriteLine( "message was sent" )
        
    Catch exp As SmtpTerminatedException
        Console.WriteLine(exp.Message)
    Catch exp As SmtpServerException
        Console.WriteLine("Exception: Server Respond: {0}", exp.ErrorMessage)
    Catch exp As System.Net.Sockets.SocketException
        Console.WriteLine("Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.ComponentModel.Win32Exception
        Console.WriteLine("Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.Exception
        Console.WriteLine("Exception: Common: {0}", exp.Message)
    End Try
 
End Sub

Open in new window

0
DamionasCommented:
If you truely can't get out on port 25, I would recommend looking at http://www.http-tunnel.com.

Downside, this client that replays information out port 80 would need to be installed on each client, you could how ever integrate our application with it, by pre-setting up the configuring and making it part of the install. I know its stretch, but its possible :)
0
DamionasCommented:
Actually, I forgot they provided an ActiveX version for tunneling, so never mind about the client integration. You could you just this : http://www.http-tunnel.com/html/solutions/http_tunnel/activex.asp
0
SteveH_UKCommented:
OK.  Lots of comments here!

Not getting a response on PING is not particularly important.  Some routers/firewalls are configured to ignore or block them.

A correct telnet connection to an SMTP server can look like nothing visible. Normally, the server will issue a welcome string but it can take quite a few seconds for that to appear.  Depending on the configuration of the SMTP server, it may respond differently.

It does sound like a firewall issue and the comment about not using a public DNS name is a good one if you are on the same network as the e-mail server.  Otherwise you can get a three way connection path:  you connect via the firewall, which connects you to the server and the server responds directly to you.  This will not work because your computer is expecting the response from the firewall.

If you are connecting from a dial-up/ADSL you may be limited because your ISP is blocking SMTP traffic.  This is a very common tactic because almost all dial-up/ADSL users should only use the ISPs SMTP server.

Can you describe your network layout further.  Where is the SMTP server, why are you trying to use that server and where is your application situated?  These will help an informed response.

Thanks.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EYoungAuthor Commented:
SteveH UK:  Thank you again for all your help and for sticking with me on this project.  I have increased the points to 250.  Now to your questions...

It appears that I am getting a good connection when I remote out to another client's computer and type in the telnet statement in the command window.  I have confirmed this with a friend who is a tech.  However, I still get the connect failed message when I try that from my development computer.

My network layout is:  one file server and my work station.  I use DSL which comes from AT&T/Yahoo into a SpeedStream modem then into a LinkSys router then into the file server then into my networked workstation.  I am running Windows XP on my workstation, Windows 2000 on the file server.  There is no email program installed or running on my worksttion or file server.  Because I am all over the area, I only use web mail through Earthlink.

Because there is no email program installed on my computer, I don't think there is an SMTP Server on my workstation or the file server.  Therefore, I use a friend's SMTP Server for testing.  That server is:  mail.haciendadata.com.  You can try the telnet command if you want.  The reason I am using that Hacienda Data server is because I do not have one (apparently) on my computer and I just need one to test my application with.  Right?

The VB6 application still gets generates the Transport error when run from my workstation.  I did installed it on the remote client's computer and it also generated the same Transport error message.  I am surprised it would do that on the remote as I can successfully execute the telnet command from that computer.

The tech friend said that he thinks AT&T blocks port 25 to everywhere but their own mailserver as an anti-spam measure.  Will check that out and to see if I can use AT&T's server.

Any more ideas?  Thanks
0
EYoungAuthor Commented:
OK, the problem seems to be that my ISP is blocking access to port 25.  It does not appear there is anything I can do to resolve that.  Thanks for all the help.  The program now does work from the remote client's computer when I use this code:
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = "eric.young@haciendadata.com"
    objEmail.To = "phoenixesy@earthlink.net"
    objEmail.Subject = "Final Test 6 Subject Line From Eric"
    objEmail.TextBody = "Test 6 from Eric, final text"
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
            "mail.haciendadata.com"
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send

Not sure why this code works and the other code does not work.
0
SteveH_UKCommented:
Thanks for the points.

Your comments:

"OK, the problem seems to be that my ISP is blocking access to port 25.  It does not appear there is anything I can do to resolve that.  Thanks for all the help.  The program now does work from the remote client's computer when I use this code:
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = "eric.young@haciendadata.com"
    objEmail.To = "phoenixesy@earthlink.net"
    objEmail.Subject = "Final Test 6 Subject Line From Eric"
    objEmail.TextBody = "Test 6 from Eric, final text"
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/c onfigurati on/sendusi ng") = 2
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/c onfigurati on/smtpser ver") = _
            "mail.haciendadata.com"
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/c onfigurati on/smtpser verport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send

Not sure why this code works and the other code does not work."

The issue as you correctly diagnose is that ISPs often block port 25.  The reason is that most spam e-mail is sent from dial-up and home network connections, and the ISPs are responsible for the network traffic that originates from their connections.  Unless you have a corporate agreement with the ISP, they will generally not allow you to use any other SMTP connection.  Additionally, many smaller organisations actually use the ISPs SMTP service as it can reduce network traffic.

You can probably use your own ISPs SMTP server from your own network if that helps you address testing issues.  I would make the choice of SMTP server configurable, so that you can make it work in multiple locations.
0
EYoungAuthor Commented:
Thanks.  Good suggestion.  I just added an option to change the SMTP Server and port.  Now the user can use any server they want.

What I still don't get is why the new code shown above works and the old code you and I were using did not.  Both used port 25 and the same SMTP Server.

Regards and thanks again, EYoung
0
SteveH_UKCommented:
I can see two possible reasons for the differing behaviour:

1)  The first attempt specifies basic authentication.  It is almost certainly failing if the credentials were intended for a different SMTP server.  Authenticating to an SMTP server can often be required as they do not allow you to send e-mail to other systems unless you can prove you are authorised to do so.  However, many ISPs block access to their SMTP servers by IP address and route, rather than by using authentication and so you may not need authentication.  Additionally, attempting to authenticate may break the connection because the credentials are invalid.
2)  The second attempt doesn't use the constant strings.  However, the code does not indicate the type of the constants and it is possible that the Configuration.Fields.Item(x) method responds differently to an unknown constant type (Variant) and an explicit string type (BSTR).  Specifying Const x As String = "xxxxxxx" may be a better approach.

Hope that helps, and thanks for the points :)
0
EYoungAuthor Commented:
Your welcome for the points.  I really appreciate the extra effort and patience you have shown throughout this process.

Are you in the UK?  I am in California, US.  It is amazing how we can collaborate with other techs around the world.  I got some help last year from someone in Australia.  Pretty amazing to me.  Thanks.
0
SteveH_UKCommented:
I am in the UK, yeah.  It is a pretty cool thing, isn't it!  I haven't used EE for questions yet, but I plan to when the right technical question is causing me grief.  I like the fact that there is a community of (varying quality!) experts willing to put time into answering questions for people around the world.  Sometimes, you get a good sense of fulfilment for helping people out.  Sometimes it is just plain frustrating, but that's the way of it :)

I guess one of the things that amazes me is the range of problems it is possible to solve without having physical or remote access to the problem environment.
0
EYoungAuthor Commented:
Amen.  Good points.  Take care.
0
EYoungAuthor Commented:
SteveH UK:  Can you also look at this question for me?  Thanks

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23172364.html
0
SteveH_UKCommented:
Sorry for not getting back to you on the other question.  I agree with the solution you picked.   VB.NET or direct Win32 coding (not recommended!) would provide alternatives, but VB6 does not directly.
0
EYoungAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.