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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I email w/ VB?

Status
Not open for further replies.

boomers

Programmer
Jul 17, 2001
9
0
0
US
I need to know how to email with VB. I have been all over the internet looking for codes and have found some but I can't get them to work. Does anyone have suggestions. I would like it to be able to open a default email client off of a computer and insert the email address in the proper spot, then either make an attachment or paste info from excel into the body of the email. Here is one program that I found that I would really like to use but I can't get it to work. So if you can please either try to figure this out or give me other suggestions.

Declarations:
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

Actual Program:
Public Function OpenEmail(ByVal EmailAddress As String, _
Optional Subject As String, Optional Body As String) _
As Boolean

Dim lWindow As Long
Dim lRet As Long
Dim sParams As String

sParams = EmailAddress
If LCase(Left(sParams, 7)) <> &quot;mailto:&quot; Then _
sParams = &quot;mailto:&quot; & sParams

If Subject <> &quot;&quot; Then sParams = sParams & &quot;?subject=&quot; & Subject

If Body <> &quot;&quot; Then
sParams = sParams & IIf(Subject = &quot;&quot;, &quot;?&quot;, &quot;&&quot;)
sParams = sParams & &quot;body=&quot; & Body
End If

lRet = ShellExecute(lWindow, &quot;open&quot;, sParams, _
vbNullString, vbNullString, SW_SHOW)

OpenEmail = lRet = 0

End Function

sub send_email()
OpenEmail &quot;feedback@freevbcode.com&quot;, &quot;Hello&quot;, &quot;We really like your web site.&quot;
end sub

I got this code from here:

Thanks
Bob If you, or you know someone that provides daycare, (such as the person running your childs daycare), have them go to This is a software for in-home child care providers that will help them greatly
 
Thanks for the reply but I don't have the CDO 1.21 in my references section of my VB Software. I am using the Visual Basic Software that comes eith Excel. Is that what the problem is?
If you, or you know someone that provides daycare, (such as the person running your childs daycare), have them go to This is a software for in-home child care providers that will help them greatly
 
The 'Visual Basic' that comes with Excel is Visual Basic for Applications (VBA), which does indeed suffer some limitations in comparison to the full product.
 
Thanks for telling me about the difference in the two programs. Also do you know what the CDO 1.21 is? If you, or you know someone that provides daycare, (such as the person running your childs daycare), have them go to This is a software for in-home child care providers that will help them greatly
 
boomers,

CDO is Collaborative Data Objects, its part of Messaging API(MAPI). You have to have VB 6.0 Developers edition for it.
VBA for the Word, Excel and Access do have this additive.
Aaron
 
Were can I get this Additive? It isn't in my references in my VB from excel If you, or you know someone that provides daycare, (such as the person running your childs daycare), have them go to This is a software for in-home child care providers that will help them greatly
 
I have the CDO 1.2 object (not the 1.21).

When I try to code the example shown in the FAQ, it doesn't pull up any MAPI object(s) when instanciating the MAPI objects.

Is this something CDO 1.21 spcific, or should 1.2 be able to handle this as well? Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Who cares how time advances? I am drinking [beer] today.&quot; Edgar Allan Poe
 
My other question is:

how can I send an email from VB without signing on to an exchange or mail account? I am trying to develop my program for people who don't have Outlook installed.

Thanks! Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Who cares how time advances? I am drinking [beer] today.&quot; Edgar Allan Poe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top