E-mail from VB
E-mail from VB
(OP)
Does anyone know how to automatically mail a document using VB, how to write a message and heading on the e-mail, and attach a document.
Thx in advance
Derrick
Thx in advance
Derrick
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS Come Join Us!Are you an
Engineering professional? Join Eng-Tips Forums!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting GuidelinesJobs |
|
RE: E-mail from VB
RE: E-mail from VB
It's on tek-tips.com
Look for Thread222-504286
You can use the MapiSession and MapiMessage controls if you want to work with any Mapi client
Stick a MapiSession control and a MapiMessage control on a form and use this as the basis for your code:
MAPISession1.SignOn
DoEvents
mapMess.SessionID = MAPISession1.SessionID
mapMess.Compose
mapMess.MsgNoteText = "hi"
mapMess.RecipDisplayName = "fred"
'mapMess.RecipAddress = "fred@aol.com"
mapMess.ResolveName
mapMess.MsgSubject = " T E S T M E S S A G E "
mapMess.AttachmentPathName = "c:\fred.txt"
mapMess.AttachmentName = "my fred"
mapMess.Send False
MAPISession1.SignOff
Use the remmed out line instead of the line above if you want to use the full email address rather than the default address book lookup
Good Luck
johnwm
RE: E-mail from VB
the solution I have used is shown below, commented out lines can be used to add other options etc.
Sub SendMAPIMessage()
Dim MapiSession As Object
Dim MapiMessage As Object
Dim MapiRecipient As Object
Dim MapiAttachment As Object
Dim Recpt, errObj As Long, errMsg
Const mapiTo = 1
Const mapiHigh = 1
On Error GoTo MAPITrap ' Create the MAPI Session.
Set MapiSession = CreateObject("Mapi.Session")
' Log on to the session
' MapiSession.Logon profilename:="MS Exchange Settings"
MapiSession.Logon profilename:="Microsoft Outlook"
' Add a message to the Outbox.
Set MapiMessage = MapiSession.Outbox.Messages.Add
' Add the recipients of the message. Note, each recipient must be
' added separately to the Recipients collection of the Message
' object.
With MapiMessage
Set MapiRecipient = MapiMessage.Recipients.Add
' MapiRecipient.Name = "derrick.taylor@stockport.gov.uk"
MapiRecipient.Name = "Derrick Taylor"
MapiRecipient.Type = mapiTo
'Set MapiRecipient = MapiMessage.Recipients.Add
'MapiRecipient.Name = "Andrew Fuller"
'MapiRecipient.type = mapiCc
'Set MapiRecipient = MapiMessage.Recipients.Add
'MapiRecipient.Name = "Michael Suyama"
'MapiRecipient.type = mapiBcc
' Resolve each recipient's e-mail name.
Debug.Print .Recipients.Count
' For Recpt = 0 To .Recipients.Count - 1
For Recpt = 1 To .Recipients.Count
.Recipients(Recpt).Resolve showdialog:=True
Next
' Attach a file to the message.
'Set MapiAttachment = MapiMessage.Attachments.Add
'With MapiAttachment
' .Name = "Customers.txt"
' .type = mapiFileData
' .Source = "C:\Examples\Customers.txt"
' .ReadFromFile FileName:="C:\Examples\Customers.txt"
' .position = 2880
'End With
' Assign the text, subject, and importance of the message.
.subject = "My Subject"
.Text = "This is the text of my message." & vbCrLf & vbCrLf
.importance = mapiHigh
' View the message in Microsoft Exchange before sending. Set
' the ShowDialog argument to False if you want to send the
' message without viewing it in Microsoft Exchange.
.Send showdialog:=False
End With
Set MapiSession = Nothing ' Clear the object variable.
MAPIExit:
Exit Sub
MAPITrap:
errObj = Err - vbObjectError ' Strip out the OLE automation error.
Select Case errObj
Case 275 ' User cancelled sending of message.
Resume MAPIExit
Case Else
errMsg = MsgBox("Error " & errObj & " was returned.")
MsgBox "Error number " & Err.Number & "." & Chr(13) & Err.Description
Resume MAPIExit
End Select
Resume
End Sub