How to Send an Email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ananth
    New Member
    • Nov 2006
    • 75

    #1

    How to Send an Email

    Hi,
    I have an Active x control that contains a Button.On the Button Click the control should send an mail to the specified address mentioned in the command click.
    How can this be done i tried the following code .
    Code:
    Function SendMail(EM_TO, Em_CC, EM_BCC, EM_Subject, EM_Body, EM_Attachment As String, Display As Boolean)
        Dim objOA As Outlook.Application
        Dim objMI As Outlook.MailItem
        Dim obgAtt As Outlook.Attachments
        Set objOA = New Outlook.Application
        Set objMI = objOA.CreateItem(olMailItem)
        If EM_TO <> "" Then objMI.To = EM_TO
        If Em_CC <> "" Then objMI.CC = Em_CC
        If EM_BCC <> "" Then objMI.BCC = EM_BCC
        If EM_Subject <> "" Then objMI.Subject = EM_Subject
        If EM_Body <> "" Then objMI.Body = EM_Body
        If EM_Attachment <> "" Then objMI.Attachments.Add EM_Attachment, 1, , EM_Attachment
    
    
        If Display Then
            objMI.Display
        Else
            objMI.Send
        End If
        Set objOA = Nothing
        Set objMI = Nothing
    End Function
    
    
    Private Sub Command1_Click()
      SendMail "ananth_r@maargasystems.com", "", "", "Testmail", "TEST MAIL FROM OUTLOOK", "", False
      MsgBox "hai"
    End Sub
    
    'Private Sub Form_Load()
        'How to call the SendMail function. If y
        '     ou do not want a function of the main ju
        '     st use two quotes and a comma
        'instead of filling the string variable.
        '     Example of a call with a To only:
        'SendMail "SendTo@Address.com", "", "",
        '     "", "", "", True
        'The code represented here will error un
        '     less a real attachment path is specified
        '     .
      
    'End Sub
    The Problem with this is if a person runs this codes and doesnt have a outlook the entire code fails.How can this be solved
    Last edited by willakawill; Feb 21 '07, 12:21 AM. Reason: please use code tags when posting code
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Take a look at Microsoft MAPI controls

    Comment

    • ananth
      New Member
      • Nov 2006
      • 75

      #3
      Originally posted by willakawill
      Take a look at Microsoft MAPI controls
      Hello Sir,
      Is there a way of sending mail using the client's default mail client?

      I am looking for a none email client specific solution that does not involve
      specifying parameters such as mail servers etc.

      Can this be done using Visual Basic???

      Comment

      Working...