Click to See Complete Forum and Search --> : Email from VB (MAPI)
kilobravo3
Dec 8th, 2001, 05:19 PM
I have a question regarding sending email from a VB program. I read up on the MAPI, and was able to add the controls to my project and send a message. Here are the problems. It appears to be sending the mail through outlook (which is OK with me), but it pops up a message saying that my program is attempting to send a message automatically and asks if it is OK. While I understand the need for this dialog box (security), my app needs to be able to email when certain events occur, so I can't have that message pop up.
The second issue is that when I issue the send command, the message is not actually sent, but in fact placed in the outbox of Outlook. It is not actually sent until after I start Outlook. At that time it is processed as it receives my mail that I check with outlook. Since there won't be a person sitting at this machine this is not a viable option.
Any suggestions are greatly appreciated.
Kevin
Hack
Dec 9th, 2001, 07:49 AM
Couple of suggestions. For number one, here is some code you can implment to automatically and unattended, close the message box.'place in a module
Public Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hWnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Public Const NV_CLOSEMSGBOX As Long = &H5000&
Public Const API_FALSE As Long = 0&
Public Sub TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
KillTimer hWnd, idEvent
Dim hMessageBox As Long
'Replace 'Self Closing Message Box' with the title you gave to your message box.
hMessageBox = FindWindow("#32770", "Self Closing Message Box")
If hMessageBox Then
Call SetForegroundWindow(hMessageBox)
SendKeys "{enter}"
End If
Call LockWindowUpdate(API_FALSE)
End Sub
'place on your form
Private Sub Command1_Click()
'Replace the '4000' below with the number of milliseconds the message box
'will appear. 1000 milliseconds = 1 second
SetTimer hWnd, NV_CLOSEMSGBOX, 4000&, AddressOf TimerProc
Call MessageBox(hWnd, "Watch this message box close itself after four seconds", _
"Self Closing Message Box", vbInformation)
End Sub
For number two, you could replace your MAPI code with this.Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
Private Sub Command1_Click()
Dim MySubject As String
Dim MyMessage As String
MySubect = "Give this a shot"
MyMessage = "This will open the default mail for the user, and pop the message off."
ShellExecute hwnd, "Open", "mailto:MyBuddy@HisDomain.com?subject=MySubject&body=MyMessage, vbNullString, vbNullString, SW_SHOW
kilobravo3
Dec 10th, 2001, 05:20 PM
Thank you for the suggestions. I tried the second one, and it wouldn't compile (I think a misplaced quote), but I modified it so it would run(Although I'm not sure if it was the right modification. I move the quote at the end of the Shell Execute line to the end of the mailto argument). However, it just pops up the outlook window with the paramters already set.
Also, I forgot to mention that I might need the ability to attach files. Any suggestions on that?
Kevin
CadDragon
Dec 13th, 2001, 02:16 PM
Check out this thread, it should help you.....
http://www.vbforums.com/showthread.php?s=&threadid=118765
Raver
Dec 13th, 2001, 04:14 PM
I am currently using a DLL in many projects, get it there:
http://www.freevbcode.com/searchresults.asp
It's called vbSendMail, Very simple to use. The only catch is that you need an SMTP to route your message.
If you use a public SMTP sometimes it takes a while for the message to reach the destination, but if you have access to a private one, then it's a flash...
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.