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

Visual Basic And E-mailing

Status
Not open for further replies.

glyons

IS-IT--Management
Mar 26, 2002
9
0
0
US
Does anyone know how to e-mail an attachment using VB code. Every time we do it the attachment come though in the body of the e-mail not as an attachment.

Thanks for all replies
 
This is what I do.

frmEmailProgress.MAPISession1.SignOn


With frmEmailProgress.MAPIMessages1
.SessionID = frmEmailProgress.MAPISession1.SessionID
.MsgIndex = -1
.Compose
.MsgSubject = "Letters Direct Merge Data"

.RecipDisplayName = "peter@accuflight.com"
c = Space(20) & vbCrLf
c = c & "Message Sent " & Format(Now, "dd mmm yyyy") & " " & Format(Now, "hh mm")
.MsgNoteText = c

.AttachmentIndex = 0
.AttachmentPosition = 0
.AttachmentName = "" & cOutName & ".txs"
.AttachmentPathName = (cAppPath & "data\" & cOutName & ".txs")


.AttachmentIndex = 1
.AttachmentPosition = 1
.AttachmentName = "" & cOutName & ".gda"
.AttachmentPathName = (cAppPath & "data\" & cOutName & ".gda")

.Send True

End With Peter Meachem
peter@accuflight.com

Support Joanna's Bikeathon
 
Using POP3 & OutLook Express, when receiving new mails, how do I know that the msg has an attachment? If there is an attachment, how can I open it?

Many Thanks.
 
Glyons, Here is a module that I use to send email messages with attachments. It work just get and you should be able to incorporate into your application with small modifications to the code.

Sub SendMessage(Optional AttachmentPath, Optional AdditoinalAttachment, Optional HotelAttachment)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim strDeadline As String
Dim strEmail As String
Dim strBody As String
Dim strContactFN As String

'Pulling variables from a Form
strContactFN = [Forms]![Store]![ContactFN]
strEmail = [Forms]![Store]!
strDeadline = [Forms]![PrintMenu]![txtDeadline]

[COLOR=green]'This examples show how to attach multiple documents to your email.[/color]

AttachmentPath = "H:\Buyer_db\Registration FACTS sheet.doc"
AdditoinalAttachment = "H:\Buyer_db\registration form.pdf"
HotelAttachment = "H:\Buyer_db\HotelRatesInformation.doc"

strBody = “Build Body Text” [COLOR=green]<-- This string builds the body of the email[/color]


[COLOR=green]' Create the Outlook session.[/color]
[COLOR=blue]Set[/color] objOutlook = CreateObject(&quot;Outlook.Application&quot;)

[COLOR=green]' Create the message.[/color]
[COLOR=blue]Set[/color] objOutlookMsg = objOutlook.CreateItem(olMailItem)

[COLOR=blue]With[/color] objOutlookMsg
[COLOR=green]' Add the To recipient(s) to the message.[/color]
[COLOR=blue]Set[/color] objOutlookRecip = .Recipients.Add(strEmail)
objOutlookRecip.Type = olTo

[COLOR=green]' Add the CC recipient(s) to the message.[/color]
[COLOR=blue]Set[/color] objOutlookRecip = .Recipients.Add(&quot;Email Address&quot;)[COLOR=green]<-- I always CC: myself on all emails I send out.[/color]
objOutlookRecip.Type = olCC

[COLOR=green]' Set the Subject, Body, and Importance of the message.[/color]
.Subject = &quot;Subject Title goes here&quot;
.Body = strBody [COLOR=green]<-- This is created by the SQL from on top[/color]
.Importance = olImportanceHigh 'High importance

[COLOR=green]' Add attachments to the message.[/color]
[COLOR=blue]If Not[/color] IsMissing(AttachmentPath) [COLOR=blue]Then[/color]
[COLOR=blue]Set[/color] objOutlookAttach = .Attachments.Add(AttachmentPath)
[COLOR=blue]End If[/color]

[COLOR=green]' Add attachments to the message.[/color]
[COLOR=blue]If Not[/color] IsMissing(AttachmentPath) [COLOR=blue]Then[/color]
[COLOR=blue]Set[/color] objOutlookAttach = .Attachments.Add(AdditoinalAttachment)
[COLOR=blue]End If[/color]

[COLOR=green]' Add attachments to the message.[/color]
[COLOR=blue]If Not[/color] IsMissing(AttachmentPath) [COLOR=blue]Then[/color]
[COLOR=blue]Set[/color] objOutlookAttach = .Attachments.Add(HotelAttachment)
[COLOR=blue]End If[/color]

[COLOR=green]' Resolve each Recipient's name.[/color]
[COLOR=blue]For Each[/color] objOutlookRecip [COLOR=blue]In[/color] .Recipients
objOutlookRecip.Resolve
[COLOR=blue]If Not[/color] objOutlookRecip.Resolve [COLOR=blue]Then[/color]
objOutlookMsg.Display
[COLOR=blue]End If[/color]
[COLOR=blue]Next[/color]
.Display

[COLOR=blue]End With[/color]

[COLOR=blue]Set[/color] objOutlookMsg = [COLOR=blue]Nothing[/color]
[COLOR=blue]Set[/color] objOutlook = [COLOR=blue]Nothing[/color]
End Sub
Paul
paul_wilson74@hotmail.com
 
I forget mention, you will need to set a reference to Microsoft Outlook 9.0 Library.

I hope this works for you. Paul
paul_wilson74@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top