Solved

Automated e-mail from VB application

Posted on 2002-06-18
7
127 Views
Last Modified: 2010-05-02
I'm using the following code line to open Outlook with a new message containing a To: address and subject line.

ShellExecute Me.hwnd, "Open", "MailTo:myname@mailserver.com?Subject=A certain subject line", "", "", 0&


It works fine, but I'd like to be able to specify an attachment also, so the user has as little to do as possible. Is there a way to do this?

Thanks.
0
Comment
Question by:rdolivaw
7 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7090013
Here is some code that will open Outlook and mail with attachments

Sub Email()
   
    Dim objOL As Object
    Dim objEMail As Object
   
    Set objOL = CreateObject("Outlook.Application") 'opens Outlook
   
    Set objEMail = objOL.CreateItem(olMailItem) ' opens new email
    With objEMail
        .Recipients.Add "me@me.com" 'recipient's email address
        .Subject = "Your details " & x 'subject of the email
        .Body = "Details"
        'To send an attachment
        .Attachments.Add ("C:\my documents\file.txt")
        .Send
    End With
   
    Set objEMail = Nothing
       
End Sub

This should do it if I did not forget anything.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7090210
have a look at this free an easy mail object: http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
LVL 10

Accepted Solution

by:
arana earned 50 total points
ID: 7090213
outlook supports file attachments via shellexecute, but other mailers probably dont support it:

pCh = "mailto:myname@mailserver.com?subject=your_subject&body=your_body&file=" & chr(34) & "c:\autoexec.bat" & chr(34)


ShellExecute Me.hwnd, "Open", pCh, "", "",
0&
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7090378
Listening...
0
 

Author Comment

by:rdolivaw
ID: 7090650
arana:

Thanks for the help. The other two were extremely helpful, too, but since all my users have Outlook as their default e-mail program, your solution was easier than those.

Thanks to you other responders, too. Most helpful and interesting information.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7090714
Arana, i did try your code but i didn't get any attachment.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7090720
Sorry, i did try with Outlook Express ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 code to programmatically convert pdf to excel 21 70
VB 6.0 printer how to align 6 58
Reading the Contents of a Directory In Access VBA 5 58
Advice in Xamarin 21 56
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now