Solved

Sending text to an email body

Posted on 2002-04-28
9
207 Views
Last Modified: 2010-05-02
I am setting up a registration form.  I want to be able to send all the information in multiple text boxes (name, address, email, serial no, etc.) to the body of an email form that opens once the user clicks the Create button.  I also want the send to and subject line to be populated with custom info.  How can I do this?
0
Comment
Question by:perkster
9 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6975032
Please maintain your open questions:
Viewiing web images Date: 06/13/2001 07:41PM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20135035
Disable windows key (start menu key) Date: 02/04/2002 02:00PM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20263050

Thanks,
Anthony
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6975175
From where?
0
 
LVL 12

Accepted Solution

by:
roverm earned 100 total points
ID: 6975371
Hi,

Here's an example. It also reads your inbox and show the attachments in a new form:

Form1:
=CODE START==============================

VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
   Caption         =   "MAPI test"
   ClientHeight    =   5790
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9660
   LinkTopic       =   "Form1"
   ScaleHeight     =   5790
   ScaleWidth      =   9660
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtFrom
      Height          =   315
      Left            =   900
      TabIndex        =   12
      Text            =   "test@abc.com"
      Top             =   150
      Width           =   7065
   End
   Begin VB.CommandButton Command3
      Caption         =   "&Attachments"
      Height          =   390
      Left            =   8175
      TabIndex        =   10
      Top             =   3000
      Width           =   1215
   End
   Begin MSComctlLib.ListView lvInbox
      Height          =   3090
      Left            =   900
      TabIndex        =   8
      Top             =   2475
      Width           =   7065
      _ExtentX        =   12462
      _ExtentY        =   5450
      View            =   3
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      FullRowSelect   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   3
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
         Text            =   "From"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628}
         SubItemIndex    =   1
         Text            =   "Subject"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628}
         SubItemIndex    =   2
         Text            =   "Attachments"
         Object.Width           =   2540
      EndProperty
   End
   Begin VB.TextBox txtBody
      Height          =   990
      Left            =   900
      MultiLine       =   -1  'True
      TabIndex        =   6
      Top             =   1275
      Width           =   7065
   End
   Begin VB.TextBox txtTo
      Height          =   315
      Left            =   900
      TabIndex        =   5
      Top             =   525
      Width           =   7065
   End
   Begin VB.TextBox txtSubject
      Height          =   315
      Left            =   900
      TabIndex        =   4
      Top             =   900
      Width           =   7065
   End
   Begin VB.CommandButton Command2
      Caption         =   "&Get Inbox"
      Height          =   390
      Left            =   8175
      TabIndex        =   1
      Top             =   2475
      Width           =   1215
   End
   Begin VB.CommandButton Command1
      Caption         =   "&Send"
      Height          =   390
      Left            =   8175
      TabIndex        =   0
      Top             =   150
      Width           =   1215
   End
   Begin VB.Label Label5
      AutoSize        =   -1  'True
      Caption         =   "From:"
      Height          =   195
      Left            =   150
      TabIndex        =   13
      Top             =   225
      Width           =   390
   End
   Begin VB.Label lblCount
      Caption         =   "0"
      Height          =   240
      Left            =   8175
      TabIndex        =   11
      Top             =   675
      Width           =   1140
   End
   Begin VB.Label Label4
      AutoSize        =   -1  'True
      Caption         =   "Inbox:"
      Height          =   195
      Left            =   150
      TabIndex        =   9
      Top             =   2550
      Width           =   435
   End
   Begin VB.Label Label3
      AutoSize        =   -1  'True
      Caption         =   "Body:"
      Height          =   195
      Left            =   150
      TabIndex        =   7
      Top             =   1350
      Width           =   405
   End
   Begin VB.Label Label2
      AutoSize        =   -1  'True
      Caption         =   "Subject:"
      Height          =   195
      Left            =   150
      TabIndex        =   3
      Top             =   975
      Width           =   585
   End
   Begin VB.Label Label1
      AutoSize        =   -1  'True
      Caption         =   "To:"
      Height          =   195
      Left            =   150
      TabIndex        =   2
      Top             =   600
      Width           =   240
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim oOutlook As Outlook.Application
Dim oFolder As Outlook.MAPIFolder
Dim oMailitem As Outlook.MailItem

Private Sub Command1_Click()
Dim oMessage As Outlook.MailItem

    Set oMessage = oOutlook.CreateItem(olMailItem)
    With oMessage
        '.SenderName '= txtFrom.Text
        .To = txtTo.Text
        .Subject = txtSubject.Text
        .Body = txtBody.Text
        .Send
    End With
    Set oMessage = Nothing
   
End Sub

Private Sub Command2_Click()
Dim sAtt As String
Dim lst As ListItem

    Set oFolder = oOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
   
    For Each oMailitem In oFolder.Items
        Set lst = lvInbox.ListItems.Add(, , oMailitem.SenderName)
        lst.SubItems(1) = oMailitem.Subject
        If oMailitem.Attachments.Count > 0 Then
            lst.SubItems(2) = CStr(oMailitem.Attachments.Count)
        End If
        lst.SubItems(3) = oMailitem.EntryID
    Next oMailitem

End Sub

Private Sub Command3_Click()
Dim frm As Form2
Dim oAtt As Attachment

    If lvInbox.SelectedItem.Index = 0 Then
        MsgBox "Select a message first !", vbCritical
        Exit Sub
    End If
   
    If Len(lvInbox.SelectedItem.SubItems(2)) = 0 Then
        MsgBox "This message contains no attachment(s) !", vbInformation
        Exit Sub
    End If
   
    For Each oMailitem In oFolder.Items
        If oMailitem.EntryID = lvInbox.SelectedItem.SubItems(3) Then
            Set frm = New Form2
            frm.lblMessage.Caption = oMailitem.Subject
            For Each oAtt In oMailitem.Attachments
                frm.lstAtt.AddItem oAtt.FileName
            Next oAtt
            frm.Show vbModal
            Unload frm
        End If
    Next oMailitem
   
    Set oAtt = Nothing

End Sub

Private Sub Form_Load()
Dim lWidth As Long

    lWidth = (lvInbox.Width - 100) / 4
   
    Set oOutlook = New Outlook.Application
   
    With lvInbox
        .View = lvwReport
        .ColumnHeaders.Clear
        .ColumnHeaders.Add , , "From", lWidth
        .ColumnHeaders.Add , , "Subject", lWidth * 2
        .ColumnHeaders.Add , , "Attachments #", lWidth
        .ColumnHeaders.Add , , "ID", 0
    End With
   
End Sub

Private Sub Form_Unload(Cancel As Integer)
    'oOutlook.Quit
    Set oMailitem = Nothing
    Set oFolder = Nothing
    Set oOutlook = Nothing
End Sub

Private Sub txtBody_Change()
    lblCount.Caption = Len(txtBody)
End Sub

=CODE END==============================================

Form2:

=CODE START============================================

VERSION 5.00
Begin VB.Form Form2
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Message"
   ClientHeight    =   3195
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4680
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.ListBox lstAtt
      Height          =   2205
      Left            =   225
      TabIndex        =   0
      Top             =   675
      Width           =   4215
   End
   Begin VB.Label lblMessage
      Caption         =   "#"
      Height          =   390
      Left            =   225
      TabIndex        =   1
      Top             =   150
      Width           =   4215
   End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit



=CODE END==============================================

D'Mzzl!
RoverM
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 12

Expert Comment

by:roverm
ID: 6975373
btw: The code in Form1 will set a reference to the Microsoft Outlook 9.0 library. If you don't have it, just set it to another outlook version.

D'Mzzl!
RoverM
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6975998
see this free component that is using SMTP to send e-mails: http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6976240
Hi emoreau, i am here before you and i didn't post "our secret weapon".
;)
0
 
LVL 12

Expert Comment

by:roverm
ID: 6990006
Any progress here ?
0
 
LVL 12

Expert Comment

by:roverm
ID: 6991721
perkster:
Thanks for returning and closing this question.

Just one question from me: Why a B-grade ? Do you still need something ?

D'Mzzl!
RoverM
0
 

Author Comment

by:perkster
ID: 6992228
I am sorry, I meant to hit A.

My apologies.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

831 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