Solved

Example - Sending email in Vb app

Posted on 1998-12-30
3
152 Views
Last Modified: 2010-05-03
I would like to see an example of sending a simple email msg from within VB - but, I don't want to use the MAPI control.
0
Comment
Question by:edved
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 50 total points
ID: 1453240
Here is an example of using OLE Messaging to send a message:

Dim oSession As Object
 
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "MS Exchange Settings", True
Dim objMessage As Object ' Message object
Dim objOneRecip As Object ' Recipient object
 
If oSession Is Nothing Then
MsgBox "You have to log on first...."
Exit Sub
End If
 
Set objMessage = oSession.Outbox.Messages.Add
' create the recipient
Set objOneRecip = objMessage.Recipients.Add
objOneRecip.Name = "Rickcau@Microsoft.com"
objOneRecip.Type = mapiTo
objOneRecip.Resolve (True) 'Show dialog to resolve ambiguities
With objMessage ' message object
subject = "Test MAPI/OLE VB Message w/ole object - explicit"
Text = "Like you really wanted this ... please delete this test"
End With
' send the message
objMessage.Send showDialog:=False

For more information on direct MAPI calls and OLE Messaging, in the MSDN Library, see the book Win32 Messaging API (MAPI) in the Win32 SDK.

VB4: VBMAIL.ZIP MAPI sample to send/retrieve mail (VB4) at http://www.geocities.com/~scvb/allfiles.htm
0
 

Author Comment

by:edved
ID: 1453241
Mirkwood,Thanks for the reply.

Question: Are the "subject" and "text" objects string variables? How can I set the "text" object to point to a text file?
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453242
DO you mean "add an attachment" or you want to use a file as source for your email.

I think you mean the second and in that case I have to disappoint you. You just have to read the file and copy it to the text property.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now