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

Hello All Question: Is it poss 2

Status
Not open for further replies.

OttSens

Programmer
Dec 13, 2001
80
US
Hello All

Question:
Is it possible to use outlook from vb for sending emails
similar to the way that you would use excel for
spread sheets or word for docs?

Scenario:
I have a vb dialog that is used for scheduling and documenting manditory monthly meetings to track an
issue. The form has a grid of worker's and ancillary
participants that are involved. One portion of the
form is for scheduling these meetings and adding /
removing participants to / from the list of invitees.
I would like if possible once the list of invitees is
compiled to be able to press a "Send Notifications"
button and send an email to each particpant in the
background. The content would be assembled from info
on the form. The reason I am not simply using smtp
is because the users are spread across numerous
departments which all use ms exchange server in various
protected configurations so I have found that connecting
to the server for an smtp transaction is frought with
peril. I do know that ALL user's who would be sending
notifications do have ms outlook as their email client.

Thoughts?

 
Yes,

Create an outlook (or MAPI) object, Open a session, add a mail object to the outbox, fill in the details + send.

as Follows:


Set moSession = CreateObject("mapi.session")

moSession.Logon "MS Exchange Settings"

'Create a new mail message
Set objMail = moSession.Outbox.Messages.Add

' create the recipient
Set objRecipient = objMail.Recipients.Add
objRecipient.Name = strMailAddress
objRecipient.Type = CdoTo
objRecipient.Resolve

objMail.Send , showDialog:=True


moSession.Logoff

Hope this helps,

Chris Dukes
 
Here's some more help if u need it, put this code into a class module named CEMailMessage:
-----------------
'Make reference to Outlook object library
'IMPLEMENTATION
Option Explicit

Private m_oOtLk As Outlook.Application
Private m_oMlItem As Outlook.MailItem
Private m_sMsg As String
Private m_sRecipients() As String
Private m_sSubject As String
Private m_bCCUser As Boolean

Property Let Message(ByVal NewMessage As String)
m_sMsg = NewMessage
End Property
Property Get Message() As String
Message = m_sMsg
End Property

Property Let Subject(ByVal NewSubj As String)
m_sSubject = NewSubj
End Property
Property Get Subject() As String
Subject = m_sSubject
End Property

Property Let CCUser(ByVal bCC As Boolean)
m_bCCUser = bCC
End Property
Property Get CCUser() As Boolean
CCUser = m_bCCUser
End Property

Public Sub AddRecipient(ByVal Recpt As String)
If m_sRecipients(0) = "" Then
m_sRecipients(0) = Recpt
Else
ReDim Preserve m_sRecipients(UBound(m_sRecipients) + 1) As String
m_sRecipients(UBound(m_sRecipients)) = Recpt
End If

End Sub

Public Sub Send()
Dim a As Integer
Dim Rcpt As Outlook.Recipient

With m_oMlItem

If m_bCCUser = True Then
Set Rcpt = .Recipients.Add(m_oOtLk.GetNamespace("MAPI").CurrentUser)
Rcpt.Type = olCC
End If

For a = LBound(m_sRecipients) To UBound(m_sRecipients)
If m_sRecipients(a) <> &quot;&quot; Then .Recipients.Add m_sRecipients(a)
Next a

.Body = m_sMsg
.Subject = m_sSubject

.Send

End With

End Sub

Private Sub Class_Initialize()
Set m_oOtLk = New Outlook.Application
Set m_oMlItem = m_oOtLk.CreateItem(olMailItem)
ReDim m_sRecipients(0) As String

End Sub

Private Sub Class_Terminate()
Set m_oOtLk = Nothing
Set m_oMlItem = Nothing

End Sub
-------------------

-------------------
'USAGE:
Dim EMail As CEMailMessage
Set EMail = New CEMailMessage

EMail.Subject = &quot;Here's my subject line&quot;
EMail.CCUser = True 'Carbon-copies sender if True
EMail.Message = &quot;Here's the body of the message&quot;

EMail.AddRecipient &quot;John.P.Smith@somecompany.com&quot;
EMail.AddRecipient &quot;Your.Address@yourdomain.com&quot;
'Add other recipients as necessary

EMail.Send

Set EMail = Nothing
------------------------

Good luck!

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
This is exactly the sort of things I need!
Kudo's to all!
As soon as I have a free monent or two to
try this out I'll do so.

Cheers....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top