Results 1 to 10 of 10

Thread: Sending email

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Sending email

    I have seen an example of sending an email using CDO, MAPI and Outlook in the March number of "Visual Basic - Programmers Journal". Does any on have this source code, or an other example of sending emails using these options?

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    All of these example require outlook. Better to send using SMTP and winsock.

    MAPI, by Arron Young

    Code:
    Private Sub cmdSendMail_Click()
        ' Sign On using the Default MAPI Account
        MAPISession1.SignOn
        
        With MAPIMessages1
            ' Use the session we just started
            .SessionID = MAPISession1.SessionID
            ' Start Composing a New Email
            .Compose
            ' Who are we sending the email to?
            .RecipAddress = "[email protected]"
            ' What's the Subject Line of the Email?
            .MsgSubject = "MAPI SendMail Example"
            ' What's the content of the Message body?
            .MsgNoteText = _
            "This is an example of how To send emails with VB via the " & vbCrLf & _
            "MAPI Mail Controls." & vbCrLf & vbCrLf & _
            "This example also includes Multiple Attachments..." & vbCrLf & vbCrLf & _
            "- Aaron Young."
            
            ' Add the First attachment:
            ' First, Set the Attachment Index To the Next available Index Number
            .AttachmentIndex = .AttachmentCount
            ' Set the Name To display with the Attachment (usually the Filename)
            .AttachmentName = "SomeFile1.txt"
            ' Set the Path (Locally) To the File To attach
            .AttachmentPathName = "C:\SomeFile1.txt"
            ' Set the Type of Attachment (Data In most cases)
            .AttachmentType = mapData
            
            ' Repeat the process To add Multiple attachments:
            .AttachmentIndex = .AttachmentCount
            .AttachmentName = "SomeFile2.txt"
            .AttachmentPathName = "C:\SomeFile2.txt"
            .AttachmentType = mapData
            
            .AttachmentIndex = .AttachmentCount
            .AttachmentName = "SomeFile3.txt"
            .AttachmentPathName = "C:\SomeFile3.txt"
            .AttachmentType = mapData
            
            ' Finally, Send the Email:
            .Send
        End With
        
        ' Close the MAPI Session.
        MAPISession1.SignOff
        
    End Sub
    Outlook:

    Code:
    Private Sub Command1_Click()
        Dim objOutlook As New outlook.Application
        Dim objOutlookMsg As outlook.MailItem
                
        Set objOutlookMsg = objOutlook.CreateItem(olMailItem)    
        
        With objOutlookMsg
            .To = "[email protected]"
            .Subject = "Testing..."
            .Body = "Testing email example"
            .Attachments.Add "C:\Winzip.txt", olByValue, 1, "Hello"
            .Send
        End With
        Set objOutlookMsg = Nothing
    End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Great, thanks!
    What component do I have to add using Outlook? An error occurs running your source code.

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Set a reference to outlook via project --> references. It will be there: Microsoft Outlook 9.0.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Also the MAPI fails, an RTE 424 appears. I have checked the MAPI in Components.

  6. #6
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Have you drawn them on your form?

  7. #7
    Junior Member
    Join Date
    Nov 2000
    Location
    Kalpetta,Wayanad,Kerala,india
    Posts
    25

    Unhappy send email

    can you use this

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Const SW_SHOWNORMAL = 1
    Const email = "[email protected]"

    Private Sub Form_Load()
    ShellExecute 0&, vbNullString, "mailto:" & email, vbNullString, "C:\", SW_SHOWNORMAL
    Unload Me
    End Sub

  8. #8
    New Member
    Join Date
    Oct 2005
    Posts
    2

    Re: Sending email

    hi i have used exactly that code for outlook and went into reference and could only see microsoft outlook 10.0 object libary so i ticked this and when it trys and sends it says something is being sent do you want to allow this and you press yes and then you check in outlook outbbox and its there but hasnt been sent. why is this?

  9. #9
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Sending email

    What if you don't have Outlook. I use Outlook Express which I can't see any reference to.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  10. #10
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346

    Re: Sending email

    This little program does just as it says... it sends emails without the need for Outlook and any extra components...
    All that is required is winsock...
    Attached Files Attached Files
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width