sramaswa
asked on
sending email from VB application
I need to send email from my VB application. How do I do it? My application runs in DOS prompt and accepts command line arguments. Should I use MAPI or Winsock object?
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
Const SW_NORMAL = 1
sURL = "mailto:ChuckyCheese@PP.co m"
ShellExecute hwnd, "open", sURL, vbNullString, vbNullString, SW_NORMAL
Const SW_NORMAL = 1
sURL = "mailto:ChuckyCheese@PP.co
ShellExecute hwnd, "open", sURL, vbNullString, vbNullString, SW_NORMAL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi, another sample use Outlook Object: http://www.vbsquare.com/articles/outlook1/index.html
useful link: http://c1082797-a.aurora1.co.home.com/datafast/CodeOutlookMail.asp
useful link: http://c1082797-a.aurora1.co.home.com/datafast/CodeOutlookMail.asp
http://www.siteexperts.com/tips/backend/ts12/page1.asp
If you have win2000 running, you can use this sample code as well. THis will uses cdonts to send email. The concept behid this is by creating a vb script file which contains the the database connectivity, the email content as well. T oinvoke this vbs file just at your dos prompt and type cscript email.vbs
If you have win2000 running, you can use this sample code as well. THis will uses cdonts to send email. The concept behid this is by creating a vb script file which contains the the database connectivity, the email content as well. T oinvoke this vbs file just at your dos prompt and type cscript email.vbs
'make sure that on the default e-mail use of MAPI server is allowed
Option Explicit
'2 controls Microsoft MAPI Control 6.0 -> MAPISession and MAPIMessages
Private Sub Command1_Click()
Dim msg As String
Screen.MousePointer = vbHourglass
msg = "This is a test email"
With Me
.MAPILogOn.SignOn ' use current user
Do While .MAPILogOn.SessionID = 0
DoEvents ' need to wait until the new session is created
Loop
Call SendToEmail("iboutchkine@h
.MAPILogOn.SignOff
End With
Screen.MousePointer = vbNormal
End Sub
Private Sub SendToEmail(ByVal Email As String, ByVal msg As String)
With MAPIMessages1
'create a new message and address it
.SessionID = MAPILogOn.SessionID
.Compose
.RecipDisplayName = Email
.AddressResolveUI = True
.RecipAddress = "smtp:" & Email
.MsgSubject = "VB GENERATED E-MAIL"
'attachment
' .AttachmentPathName = "c:\a\a.htm"
.MsgNoteText = msg
.Send False
End With
End Sub