-
Sending Email from VB6 application
OS=Windows XP SP3; VB6-Enterprise Edition
I have done a lot of searching for snippets of code that will allow a user to send an e-mail. I can not find what I need nor I don't understand the code.
This is what I am looking to do:
To make things easy, I'll have a menu item that will say "Send for Technical Support". What I want to happen when the user clicks on that menu item is for his/her email client to come up. When that window shows, I will have my e-mail address in the "To" and the words "Technical Support" in the Subject.
All the user needs to do is to fill in the body of the text and send the e-mail. Control needs to return back to the VB application.
Can anyone help me out with a sample of code or the actual code I need to write.
Thank you,
Sam
-
Re: Sending Email from VB6 application
vbSendMail is arguably best free email client out there.
It uses winsock and is very simple to implement so give it a try.
-
Re: Sending Email from VB6 application
However, if you want (as you asked) THEIR default email client to come up, a simple mailto: should suffice...done through a browser window, it usually invokes the default mail client. If you also want to add subject and stuff there's ways to do that, google "mailto options" and you should find more info :-)
-
Re: Sending Email from VB6 application
Quote:
Originally Posted by
RhinoBull
vbSendMail is arguably best free email client out there.
It uses winsock and is very simple to implement so give it a try.
The instructions state "You also need a reference to the vbSendMail component in the Project References"
Question: Where do I find the references for vbSendMail and how do I put them in Project Reference area?
-
Re: Sending Email from VB6 application
-
Re: Sending Email from VB6 application
Quote:
Originally Posted by
SamC
The instructions state "You also need a reference to the vbSendMail component in the Project References"
Question: Where do I find the references for vbSendMail and how do I put them in Project Reference area?
Reference becomes available after dll gets registered.
I thought someone who does this [apparently] since 2005 would know that.
Besides, zip file contains VBG files which stand for VBGroup so when it is loaded it will include multiple projects - one of them is "main" and one is dll.
Your main project will already have dll referenced so all you need to do is run it.
Regards.
-
Re: Sending Email from VB6 application
Okay: I added vbsendmail.dll to system32 directory and created the "References" entry.
Here's the code I copied and ran:
Code:
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
Looking at this statement
Code:
poSendMail.SMTPHost = txtServer.Text
How do I find this value?
I am confused with this: For example: User1 might be using Outlook; User2 might be using Incredimail. The SMTP host will vary. So programmatically, how do I find the value?
Sam
-
Re: Sending Email from VB6 application
You don't - it's a user input field. Here is list of major providers.
-
Re: Sending Email from VB6 application
Quote:
Originally Posted by
RhinoBull
You don't - it's a user input field. Here is
list of major providers.
I'm sorry but I'm, still confused. I saw the list of Servers but I don't know what to do with it.
If I plug the Server Name in the textbox, How do I determine what server the user has?
I need some "hand holding".If you can explain it in a few lines of code, I would appreciate it.
Sam
-
Re: Sending Email from VB6 application
From wikipedia
Quote:
While electronic mail servers and other mail transfer agents use SMTP to send and receive mail messages, user-level client mail applications typically only use SMTP for sending messages to a mail server for relaying...
...as I understand, the 'user' send the mail as a message to the SMTP server typed in the textbox and this SMTP server actually send the mail
-
Re: Sending Email from VB6 application
look at the setting used by the current email client, it is generally related to the isp providing service,
vbsendmail does try to determine the default client without input from the user, sometimes works sometimes does not
if they have no smtp server available, the user would have to look at setting up an account for one, with a free service such as gmail or gmx
-
Re: Sending Email from VB6 application
MAYBE, I am approaching this problem the WRONG WAY. Let me ask those of you with experience how you would handle this problem.
This is what I am trying to do:
I am writing an application that will be distributed to many users. If they run into any problems, I want to be notified. I have seen in many applications, usually in the "HELP" menu a link that might say "For Support...." or on a form, a Text box that would say "Enter your e-mail address". When the link is clicked your clients e-mail comes up and the user types in the body and sends the e-mail. Control returns back to the program.
Now, I DO NOT NEED TO DO IT THIS WAY but I am asking you professionals how I should handle the problem. Maybe this is more of a "design" question? If you wrote an an application and the user had a problem, how would you tell the user to contact you? Would you just give them an e-mail address or would you enhance that by bringing up the user's e-mail client OR would you do it a totally different way? If so, how?
Thanks,
Sam
-
Re: Sending Email from VB6 application
Quote:
how would you tell the user to contact you
transferring the error details to a webserver or developer by email
-
Re: Sending Email from VB6 application
Try logging all errors to a text file and send it to the webserver or send it as an email to you.. :)
-
Re: Sending Email from VB6 application
for the user to contact you
you can use mailto: from shellexecute to fill an email in there default email client, to which they can add more information, then click send, this is probably the most useful method
to autosend details or log files, in background with no user interface i would use cdo.message, but vbsendmail would work as well, if unsure about the users stp server you could send all, from an account of your own from some free stmp server such as gmail or gmx
you can not use vbsendmail with gmail as gmail uses ssl, but there is code samples in this forum for using cdo.message to send through gmail
-
Re: Sending Email from VB6 application
I have a problem with this too.
i've downloaded some source code, included the vbmaildll.
no success at all.
vbmaildll is the only program that show me exactly the reason of fail.
the reason is issue STARTTSL,
i looked in google, and i understand this is some format you need to include in the mail, but i couldn't figure out how.
maybe someone know something ?
EDIT: in general what i'm trying to do is, send a mail to valid email, from my pc, without login to some mail first.
is this possible ?
-
Re: Sending Email from VB6 application
afaik
tsl is a secure socket, vbsendmail does not support secure sockets, you would need to modify the source code of the sendmail application
or use some alternative
Quote:
like Secure Socket Layers (SSL) and Transport Security Layer (TSL), ...
Quote:
send a mail to valid email, from my pc, without login to some mail first
you always have to login to some server, though it can be done in background
-
Re: Sending Email from VB6 application
@westconn1: I think setting the port to 465 will work... Not sure about this... I have faced the same problem, when a Gmail account is used in vbsendmail...
-
Re: Sending Email from VB6 application
i have no problem doing that in cdo, but have never had success in vbsendmail
cdo has a setting to use ssl
-
Re: Sending Email from VB6 application
wetscon1
i found this
Code:
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "[email protected]"
objMessage.To = "[email protected]"
objMessage.TextBody = "This is some sample message text."
objMessage.Send
but it fails with run time error
that the senduse doesn't set or somthing.
can you please post a working example
how to send simple text, (+ maybe one attach file)
to hotmail.com/gmail.com
the smtp is
smtp.live.com
smtp.gmail.com
(incase you forgot :) )
thanks ahead.
-
Re: Sending Email from VB6 application
See this thread: CDO Mail
westconn1 had posted some code: westconn1's reply
For more, do a search on the forums for CDO :wave:
-
Re: Sending Email from VB6 application
thank you very much.
yes, the code of westconn1 works fine for gmail.com
and this can be enough for what i need,
though i would like to know, how to access smtp.live.com too.
i hope there is an option to configure tsl connection in cdo.
if someone know, please help :)
-
Re: Sending Email from VB6 application
usessl parameter (as set in the code for gmail) should work, gmail uses a secure server, change the server and port etc to suit whatever server you wish to use
if the user has a smtp email client already set up you can default the code to use that default server, but sendusing = 2 is required (use transport, for all external emails)
there is some constants used for sendusing (and other values), but i can not remember what they are
-
Re: Sending Email from VB6 application
thanks man, but i have to tell you something.
about 2 days ago, i could quite easy success with send to gmail.com
today i spent about 2 hours, trying to send , with a cleaner code, but couldn't successed.
after about 2 hours i looked into the mail, in the recieved mails that i did
2 days ago, and i got it.
your code has only one problem.
the "to" field has to be a valid email address.
i mean it can't be "me" as in your code, but it can be "[email protected]"
wow, at least i found it,
now other time i'll check the live.com server.
so please fix your code, so others won't spent hours like me :)
anyway thank you very much for your code, it was a really great help for me,
i was badly needed it.
-
Re: Sending Email from VB6 application
i did assume anyone using the code would at least try sending to a valid email address
-
Re: Sending Email from VB6 application
Not sure if this would be of help but the mail retrieval project in my sig shows how to use Visual Basic 6.0 to send an email through Office Outlook.
-
Re: Sending Email from VB6 application
Quote:
Originally Posted by
whatsup
I have a problem with this too.
i've downloaded some source code, included the vbmaildll.
no success at all.
vbmaildll is the only program that show me exactly the reason of fail.
the reason is issue STARTTSL,
i looked in google, and i understand this is some format you need to include in the mail, but i couldn't figure out how.
maybe someone know something ?
EDIT: in general what i'm trying to do is, send a mail to valid email, from my pc, without login to some mail first.
is this possible ?
vbSendMail has WithEvents to trap errors:
Code:
Option Explicit
Private WithEvents poSendMail As vbSendMail.clsSendMail
Private Sub Command1_Click()
Call SendNotificationEmail("x", "Test", "test subject")
End Sub
Private Sub poSendMail_SendFailed(Explanation As String)
MsgBox ("Your attempt to send mail failed for the following reason(s): " & vbCrLf & Explanation)
End Sub
Private Sub SendNotificationEmail(ByVal pTo As String, _
ByVal pMessage As String, _
ByVal pSubject As String, _
Optional ByVal pCC As String = "")
10 On Error GoTo ErrorHandler
20 Set poSendMail = New vbSendMail.clsSendMail
30 poSendMail.SMTPHost = "Yourhost.com"
40 poSendMail.From = "[email protected]"
50 poSendMail.FromDisplayName = "DoNotReply.com"
60 poSendMail.Recipient = "[email protected]"
70 poSendMail.CcRecipient = "[email protected]"
80 poSendMail.Subject = pSubject
90 poSendMail.Message = pMessage
100 poSendMail.Send
110 Set poSendMail = Nothing
120 Exit Sub
ErrorHandler:
130 Err.Raise Err.Number, Err.Source & " [" & "SendEmailNotification Line: " & Erl & "]", Err.Description
End Sub
-
Re: Sending Email from VB6 application
Quote:
Originally Posted by
westconn1
i did assume anyone using the code would at least try sending to a valid email address
you are right, but i'm very new to internet stuff,
so in the begining i didn't understand exactly what i'm doing.
now i understand, and i also understand, that probably, there is no way
to send a mail somewhere without login to a mail, first.
so now i learned 2 things, how to login to a mail, and how to send a mail.
thank you very much.
now i need similar thing, login to messenger account through the web page, with winsock.
sending request, waiting for respond and then sending the user name and password,
the only problem is that i don't exactly how to do that, yet. :)
-
1 Attachment(s)
Re: Sending Email from VB6 application
Since the original question was how to bring up the default mail client with the TO and SUBJECT fields filled in, I have attached a sample project using ShellExecute to accomplish just that.