Solved

Sending text to an email body

Posted on 2002-04-28
9
203 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
Comment Utility
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
Comment Utility
From where?
0
 
LVL 12

Accepted Solution

by:
roverm earned 100 total points
Comment Utility
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
 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
Hi emoreau, i am here before you and i didn't post "our secret weapon".
;)
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
Any progress here ?
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
Comment Utility
I am sorry, I meant to hit A.

My apologies.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

763 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

8 Experts available now in Live!

Get 1:1 Help Now