![]() |
|
|
| Subject:
How do I email from a VB6 application
Category: Computers > Programming Asked by: jstm-ga List Price: $10.00 |
Posted:
03 Mar 2005 21:25 PST
Expires: 02 Apr 2005 21:25 PST Question ID: 484454 |
I know you can email reports from Microsoft Access databases. But, know I am programming using Visual Basic 6 and need to know how I can email. How do I email from Visual Basic 6 application? |
|
| There is no answer at this time. |
|
| Subject:
Re: How do I email from a VB6 application
From: willcodeforfood-ga on 03 Mar 2005 21:32 PST |
What sort of email server will you be sending email through? MS Exchange? |
| Subject:
Re: How do I email from a VB6 application
From: jstm-ga on 04 Mar 2005 01:31 PST |
I will be using Outlook which is set up on our network. |
| Subject:
Re: How do I email from a VB6 application
From: willcodeforfood-ga on 04 Mar 2005 12:12 PST |
One of the easiest ways to send email using Exchange from VB6 in my
experience is to use the Exchange Pickup Folder. You can also use a
number of COM components such as CDONTS and there are a number of
third-party components that provide more robust functionality. I'll
just demonstrate the Pickup Folder here.
Essentially, you just write a text file to the the Pickup Folder and
Exchange does the rest automagically. The name of the file does not
matter, so use whatever filename will help you track your messages.
On any computer with the standard IIS installation, the folder is
C:\Inetpub\mailroot\Pickup. You will only have the Inetpub\mailroot
folder if you selected the SMTP Service option when installing IIS on
your computer. You can use the Add or Remove Programs applet in the
Control Panel to add this option if it is missing. If IIS is running
on a remote computer, write the file to the corresponding folder on
the remote computer. Make sure the Simple Mail Transfer Protocol
(SMTP) service is running on the computer where you are writing your
text files when you test your program. WARNING! Don't leave that
service up and running on a computer that is not behind a firewall or
it could be maliciously used by other computers to relay spam for
them.
Creating and writing to a text file from VB6 is a snap. The code
looks the same in Access 2000 and later versions by the way. Here's a
sample that I've put in a generic VB button click Sub. Note that in a
filespec, we replace each backslash "\" with a double-backslash "\\"
Private Sub Command1_Click()
Open "c:\\somefolder\\hello.txt" For Output As #1
Print #1, "hello world!"
Close #1
End Sub
So using this method, we just write a email message out to the Pickup Folder.
Private Sub Command1_Click()
Open "c:\\Intepub\\mailroot\\Pickup\\mymsg.txt" For Output As #1
Print #1, "x-sender: jason@mycorp"
Print #1, "x-receiver: leslie@mycorp"
Print #1, "From: jason@mycorp"
Print #1, "To: leslie@mycorp"
Print #1, "Subject: Results are in."
Print #1, "We have won!"
Close #1
End Sub
Some additional technical details:
http://www.windowsitlibrary.com/Content/141/09/1.html
For clarity, keep in mind that Outlook is an email client or email
reader. Exchange is the email service provider or mail delivery
system. You are using VB to send email through Exchange, not Outlook.
It is not necessary to have Outlook installed to send email through
Exchange, no matter what method one uses. |
| Subject:
Re: How do I email from a VB6 application
From: jstm-ga on 04 Mar 2005 20:31 PST |
Do I have to purchase MS Exchange? Is it something I would purchase at Best Buy? |
| Subject:
Re: How do I email from a VB6 application
From: willcodeforfood-ga on 05 Mar 2005 08:52 PST |
You said "I will be using Outlook which is set up on our network." and I was just clarifying. More exact would have been "I will be using Exchange which is set up on our network." You don't need to purchase anything. If you are on a network and use Outlook to send and receive email, then just install IIS on your local computer (including the SMTP mail portion which is not normally included by default during install). Then follow the instructions I gave in the last comment. |
| Subject:
Re: How do I email from a VB6 application
From: dound-ga on 06 Mar 2005 04:46 PST |
You can do this easily with MAPI in VB (it uses your default email
client; ie sounds like outlook for you, but this code will also work
with other popular clients like thunderbird, etc ...) -- you do not
need to go through the pain of setting up ISS simply to send emails!
Here's the solution:
1) Add the Microsoft MAPI Controls 6.0 to your project (depending on
your version of VB, you can do this under something like
Project-->Components)
2) Add a MAPISession object (named 'MAPISession1') and a MAPIMessages
object (named 'MAPIMessages1') (the default properties should be
fine).
3) Add the following code to your project:
Private Sub LogonEmail()
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
End Sub
Private Sub SendMail(ToEmail$, Subj$, Body$)
MAPIMessages1.Compose
MAPIMessages1.RecipDisplayName = ToEmail
MAPIMessages1.MsgSubject = Subj
MAPIMessages1.MsgNoteText = Body
MAPIMessages1.ResolveName
MAPIMessages1.Send
End Sub
Private Sub LogoffEmail()
MAPISession1.SignOff
End Sub
4) To use, call LoginEmail() and then call SendMail with the
appropriate to, subj, and body fields to send email. When you're done
sending email just call LogoffEmail() to sign off of the session.
Enjoy!
-- I posted an example zipped at http://www.dound.com/temp/vb6Eml.zip |
| Subject:
Re: How do I email from a VB6 application
From: jstm-ga on 06 Mar 2005 23:33 PST |
Thanks you very much dound-ga!!!! This works great!!! |
| Subject:
Re: How do I email from a VB6 application
From: jstm-ga on 07 Mar 2005 00:16 PST |
Is it possible to attached a report to the email? |
| Subject:
Re: How do I email from a VB6 application
From: dound-ga on 07 Mar 2005 17:29 PST |
Yes, but it is somewhat harder. If the report is text-based, I would consider appending it to the body of the email. If you need to actually send attachments though, then I suggest you read http://www.ilook.fsnet.co.uk/vb/vbmapi.htm -- this page has a great overview and example use of a function "AddAttachment" and is public domain. Glad to help; hopefully this has answered your questions. |
| Subject:
Re: How do I email from a VB6 application
From: inmar2002-ga on 11 Mar 2005 02:11 PST |
you can create outlook express object and send email through it. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |