E-mail attachments with VB 
Author Message
 E-mail attachments with VB

Could somebody please advise me on the best method to E-mail attachments
using VB6. I would preferably like to open a new message using the default
E-mail program and pass the message the attachment.

If it is not possible to use the users default E-mail program then any other
solutions are also greatly appreciated.

Many thanks...



Mon, 08 Jul 2002 03:00:00 GMT  
 E-mail attachments with VB
Hi Robert,

if you have a MAPI client installed on your maschine, you can use the
following code that I wrote for using with Outlook 97/98.
The sub takes 3 parameters, the receipient's email address, the path to the
attachment and the name of the file that should be attached.

Sub SendMsg(strReceipient As String, strAttachmentPath As String, strFName
As String)

  Dim objSession As Object
  Dim objMessage As Object
  Dim objRecipient As Object
  Dim objAttachment As Object

  strAttachmentPath = strAttachmentPath & strFName

  Set objSession = CreateObject("mapi.session")

  ' Logon with a valid profile name to avoid Logon Dialog:
  objSession.Logon "Robert Blomstrand",  showdialog:=False, newsession:=True

  ' Create new message:
  Set objMessage = objSession.Outbox.Messages.Add
  With objMessage
    .Subject = strFName
    .Text = "Messagetext"
  End With

  ' Add an attachment:
  Set objAttachment = objMessage.Attachments.Add
  With objAttachment
    .Name = strFName
    .Type = 1       ' mapiFileData
    .Source = strAttachmentPath
    .ReadFromFile FileName:=strAttachmentPath
    .Position = 0
  End With

  ' Add receipient:
  Set objRecipient = objMessage.Recipients.Add
  With objRecipient
    .Name = strReceipient
    .Resolve showdialog:=False
  End With

  ' Send message without dialog:
  objMessage.Send False

  objSession.Logoff

End Sub

You call the sub like shown below:


Hope, this helps,
- Jens -



Quote:
> Could somebody please advise me on the best method to E-mail attachments
> using VB6. I would preferably like to open a new message using the default
> E-mail program and pass the message the attachment.

> If it is not possible to use the users default E-mail program then any
other
> solutions are also greatly appreciated.

> Many thanks...



Mon, 08 Jul 2002 03:00:00 GMT  
 E-mail attachments with VB

Quote:
> Could somebody please advise me on the best method to E-mail attachments
> using VB6. I would preferably like to open a new message using the default
> E-mail program and pass the message the attachment.

> If it is not possible to use the users default E-mail program then any other
> solutions are also greatly appreciated.

> Many thanks...

if you have the SMTP service installed an set up you can use CDO

Dim objCDO
Set objCDO = CreateObject("CDONTS.NewMail")


objCDO.Subject = "Subject"
objCDO.Body = "Body goes here"
objCDO.AttachFile "d:\sample.txt"
objCDO.Send
Set objCDO = Nothing



Mon, 08 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Emailing Attachments In VB 6 Pro

2. VB6.0 How to send an email attachment from VB Applic

3. Sending email attachments via VB app

4. How do I send an Email attachment from VB

5. Word Mail merge to Outlook Email with PDF Attachment

6. Sending Email with Default Email Software WITH Attachment

7. Attachments for e-mail in mail merge

8. How to automate Outlook with email attachment from ASP Clinet using vb SCRIPT

9. Extracting Attachments from emails in VB?

10. Drag and drop an email attachment on an VB app

11. How to automate Outlook with email attachment from ASP Clinet using vb SCRIPT

12. Extract attachment files from an email and save it as a local file with vb

 

 
Powered by phpBB® Forum Software