-
Hi there! I mentioned this one a while ago but I'm not too sure how I should go about implementing the response.
Ok, I want send an e-mail to a pre-set e-mail address without bringing up an outlook window or allowing the user to edit the message. (The subject/body will be contained within a text box.) I would like it to be sent automaticly away from user interaction. I got told to use MAPI control or something like that. Any suggestions or code examples GREATLY appreciated! Thanks guys, you're always a great help to newbies like myself!
Rhys
-----------
Using VB 6 (learning addition - the shame of it!)
-
Here's the code I used to send an email w/ an attachment through Outlook Express. First you have to add the MAPI controls to your components. Then add one MAPISession and one MAPIMessage control to your form. Then use the following code:
Code:
MAPISession1.SignOn 'Create new Outlook Session
MAPIMessages1.SessionID = MAPISession1.SessionID 'Link session and message
MAPIMessages1.Compose 'Begin writing email
MAPIMessages1.RecipAddress = "[email protected]" 'Address to send to
MAPIMessages1.AddressResolveUI = True 'Make sure address exists
MAPIMessages1.ResolveName
MAPIMessages1.MsgSubject = "Subject" 'Subject of email
MAPIMessages1.MsgNoteText = "Body" 'Body of email
MAPIMessages1.AttachmentPathName = "C:\attachment.txt" 'Add an attachment
MAPIMessages1.Send False 'Send w/out the email showing
MAPISession1.SignOff 'End Outlook session
I hope this helps. I'm a newbie too so just hang in there.
-
First : Fire Up VB, and go to Project-> Components. Tick the Microsoft MAPI control and click OK. Now you should see 2 extra icons on your toolbox.
Add them both to your form and try this code:
Code:
MAPISession1.DownLoadMail = False
MAPISession1.SignOn
' Send Mail
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipAddress = "[email protected]"
MAPIMessages1.RecipDisplayName = "<DISPLAY RECIPIENT NAME>"
MAPIMessages1.MsgSubject = "<THESUBJECT>"
MAPIMessages1.MsgNoteText = "<THE TEXT>"
MAPIMessages1.Send
MAPISession1.SignOff
Have fun!
-
Thanks I'll try that. Just two more things, if the user is offline, will the DUN connection window pop-up? I imagine it should do and that will be fine.
The other thing, if something goes wrong will it return an error which I can handle, or is there another piece of code that checks to see if the message has been sent successfully.
Rhys
-----------
Using VB6 LE
-
As for your first question, I don't know. My app is running off of pc's with a constant cable connection. For your second question, you should be able to find the errors generated by the MAPI controls in the Help that comes w/ VB. Then just set up an error handler and handle each error accordingly.
-
I have tried to find the Microsoft MAPI controls but cannot find them anywhere. Is it something that is not included in the Learning Edition of VB or is it somewhere on my hard-drive? If so, some directions would be great! (I've searched for ocx's with the file name of MAPI.)
Rhys
--------
VB6 LE
-
I tried the code that you guys suggested, but it doesn't seem to work. Is there some settings that I need to set in order for it to work. I don't have Outlook but, I am using Outlook Express. When I run the code that you posted a dialog box comes up prompting me to choose a profile and the only one it shows is Outlook. What else do I need to do?
Thanks,
-
Yo
I use dimacs jmailer component for every email problem I have It's one of the best mailer components far better than microsoft's, download it from http://www.dimac.net
it's free and its awesome, u don't need to specify a from address etc. how many times must I say this is the ultimate mailer component!!!!!!
JFG
-
To Rhys, if you can't find "Microsoft MAPI Controls" when you click Project->Components, then I'm guessing they don't come with the learning edition. Try searching for MSMAPI32.ocx in your Windows/System folder. This is the file that contains the Mapi controls. If you have it, browse for it under Project->Components and add it. If you don't have it, you might be able to get the Mapi controls from Microsoft's website or get the one that jfg was talking about.
To ande211, is Outlook Express your default email client? I think it has to be for this to work. Go to the Control Panel, select "Internet Options", and click on the "Programs" tab. There you can see what your default client is. If your default client is not Outlook Express, I don't know if the code I posted will work. You can also try setting the MAPISession1.UserName and MAPISession1.Password properties. You said you need to choose a profile, so maybe it is looking for you to specify a user.
-
Shippy,
I made Outlook Express my default mail client and added the username and password, but it still doesn't work. I don't know what's wrong, but thanks anyways for your help.
-
Thanks shippyatdrexel but I cannot find MSMAPI32.ocx anywhere on my system. Could someone tell me how big the file is and I might be able to nick off someone here. I know I will have to register it (gulp) it should be ok though. If not, is there is anyone using the LE of VB6 that has downloaded this file, then the URL would be greatly apprreciated. Thanx.
Rhys
---------
Using VB6 LE
-
Rhys, I can send you the .ocx through email if you want. I don't know if that is all I need to send you, and it's probably not legal.
Sorry ande211. I'm sure there are some good tutorials out there. The VB Help is not too bad either.
-
Thanks shippyatdrexel, that would be a great help. I didn't realise that there was a possibility of it being illegal. Don't worry if you are uncomfortable doing it. You'll find my e-mail address in my profile.
Rhys
--------
Using VB6 LE