News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Use CDO to send email in Visual Basic 6

Started by nandagopal, Nov 04, 2008, 07:21 PM

Previous topic - Next topic

nandagopal

First add a reference to the Microsoft CDO library.

When the user fills in the fields and clicks the Send button, the program creates a CDO Message object, fills in its fields, and calls its Send method.


' Note: Add a reference to the Microsoft CDO library.
Private Sub cmdSend_Click()
Dim cdo_msg As Object

    Set cdo_msg = CreateObject("CDO.Message")

    cdo_msg.Subject = txtSubject.Text
    cdo_msg.From = txtFrom.Text
    If Len(txtTo.Text) > 0 Then cdo_msg.To = txtTo.Text
    If Len(txtCc.Text) > 0 Then cdo_msg.Cc = txtCc.Text
    If Len(txtBcc.Text) > 0 Then cdo_msg.Bcc = txtBcc.Text
    If Len(txtAttachment.Text) > 0 Then
        cdo_msg.AddAttachment txtAttachment.Text
    End If
    cdo_msg.TextBody = txtBody.Text

    cdo_msg.Send
    Set cdo_msg = Nothing
End Sub