Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send an e-mail from application

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi

Coul you please tell me how to send an e-mail from my application

Is there an object which can help me
 
Hi,


Drop me a mail. I shall send u the zip file to u.
My mail id :- mohan_sekar@yahoo.com
 
This came from Karl Moore at VBWorld:

Filling Out E-Mail Fields

You've undoubtedly clicked on e-mail links before. Ever found a Web site that automatically fills out certain fields for you?
Thanks to the API and a few lines of code, now you can do the same – in Visual Basic!
This handy procedure builds up a 'mailto:' string, along with a number of other parameters, such as the message subject line and CC recipients. It then sends this to an API call, which throws the data at your default e-mail program.
Great for kick-starting a user into mailing somebody or reporting an error to technical support.
Note: Certain users add the line - &Attach="e:\directory\file.txt" – to the strCommand string below to automate file attachments. However this doesn't seem to work with all e-mail programs, so we have left it out.

Usage

Call SendMail("karl@vb-world.net", "Overdue Payment", _
"Your current bill is: $105.09. Pay up!", _
"karl@karlmoore.com", "billing@ibeauty.com")

Code:

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_SHOWNORMAL = 1

Public Sub SendMail(Optional Address As String, _
Optional Subject As String, Optional Body As String, _
Optional CC As String, Optional BCC As String)

Dim strCommand As String

'Build up the mail string
If Len(Subject) Then strCommand = "&Subject=" & Subject
If Len(Body) Then strCommand = strCommand & "&Body=" & Body
If Len(CC) Then strCommand = strCommand & "&CC=" & CC
If Len(BCC) Then strCommand = strCommand & "&BCC=" & BCC

'Replace the first ampersand, if any,
'with a question mark
If Len(strCommand) Then
Mid(strCommand, 1, 1) = "?"
End If

'Add mailto: command and main e-mail
'address to the command string
strCommand = "mailto:" & Address & strCommand

'Execute command via the API
Call ShellExecute(Me.hwnd, "open", strCommand, _
vbNullString, vbNullString, SW_SHOWNORMAL)

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top