Solved

Send email attachment using VB?

Posted on 2003-10-29
5
1,404 Views
Last Modified: 2010-05-01
Hi. I have a piece of code that sends an email via Outlook:

Private Sub SendEmail(strProblem)

On Error GoTo errEmail

Dim objSession      As Object
Dim objMessage      As Object
Dim objRecipient    As Object
Dim strProblemFull  As String
Dim nRow            As Integer
Dim strProfileInfo  As String
Dim strMailbox      As String
Dim sSubject        As String
Dim objMsg          As Object
Dim sFrom           As String

   
   For nRow = 1 To nEmails
       
        sTemp = ""
        ' get list of emails for the report type and group
        lRet = GetPrivateProfileString("Email", "Subject", "", sTemp, Len(sTemp), sINI)
        'Set the properties of the message object
        sSubject = Replace(Trim$(sTemp), Chr(0), "")
       
        sTemp = ""
        ' get list of emails for the report type and group
        lRet = GetPrivateProfileString("Email", "from", "", sTemp, Len(sTemp), sINI)
        'Set the properties of the message object
        sFrom = Replace(Trim$(sTemp), Chr(0), "")
       
        sTemp = ""
        ' get list of emails for the report type and group
        lRet = GetPrivateProfileString("Email", "To" & CStr(nRow), "", sTemp, Len(sTemp), sINI)
       
        Set objMsg = CreateObject("CDO.Message")
        objMsg.From = sFrom
        objMsg.To = Replace(Trim$(sTemp), Chr(0), "")
        objMsg.Subject = sSubject
        objMsg.TextBody = strProblem
        objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "abzexmb1"
        objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        objMsg.Configuration.Fields.Update
        objMsg.Send
        Set objMsg = Nothing

    Next
       
     
Exit Sub

The details for the email (to, from etc) are held in an ini file:
[email]

noofEmails=1
frequency=7
subject=
from=
to1=

This works fine but I want to be able to send an attachment along with the email (access db). Does anyone know how to do this?

Thanks.

0
Comment
Question by:Mhairijm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9642695
you could use this exelent a free component:
http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
ID: 9642714
Also, there is an .Attachment collection if i rememeber well in Outlook
0
 

Author Comment

by:Mhairijm
ID: 9642748
Thanks. I'll have a look and let you know how I get on.
0
 

Author Comment

by:Mhairijm
ID: 9643427
.Attachment works a treat, thanks!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9643624
Glad to help.
Thanks for "A" grade.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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