Solved

How to send Itself in an Email to an address that a person types in?

Posted on 2004-10-09
6
216 Views
Last Modified: 2010-05-18
Im making a Game in Visual Basic and im putting an "email to friend" option in a menu and I want it so when they click on "send to friend' it will ask for an email address and then type an address in and click ok and it will send itself to that person.  What would be the code for this?  Thanks
0
Comment
Question by:jrolson
  • 3
  • 2
6 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 12267888
The code for this depends on what you plan to use to send the email with.  Will it be Outlook, SMTP, or what?
0
 

Author Comment

by:jrolson
ID: 12267898
It will be Outlook I guess.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12267933
Ok.  I'll provide a code sample showing how to send a message from Outlook.  However, Microsoft has implemented a security feature in Outlook that will pop a dialog box up each time you send a message.  It's a guard against a virus sending emails without your knowledge.  Some folks find it extremely annoying.  There's no easy way around it without using a third-party tool.  With that in mind, are you sure you want to use Outlook?
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 76

Accepted Solution

by:
David Lee earned 125 total points
ID: 12267968
Here's the code for sending via Outlook.  All you'll need to do is specify the profile name in place of "ProfileName" and fill in the other values.

Private Sub SendMessage()
    'Include a reference to Microsoft Outlook x.x Object Library
    'Where x.x is your version of Outlook
    Dim objApp As New Outlook.Application, _
        objNS As Outlook.NameSpace, _
        objMessage As Outlook.MailItem
    Set objNS = objApp.GetNamespace("MAPI")
    objNS.Logon "ProfileName"
    Set objMessage = objApp.CreateItem(olMailItem)
    objMessage.To = "Recipient's Address"
    objMessage.Subject = "Subject"
    objMessage.BodyFormat = olFormatHTML 'Assuming you want to use HTML format
                                         'for the message body
    objMessage.Body = "Message"
    objMessage.Send
    Set objMessage = Nothing
    objNS.Logoff
    Set objNS = Nothing
    Set objApp = Nothing
End Sub
0
 

Author Comment

by:jrolson
ID: 12268525
Thanks
0
 
LVL 12

Expert Comment

by:BobLamberson
ID: 12268998
Hi jrolson,
You might want to look at the clickyes freeware to help with the popup dialog David mentioned.
http://www.contextmagic.com/express-clickyes/

Bob
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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

895 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

11 Experts available now in Live!

Get 1:1 Help Now