Results 1 to 3 of 3

Thread: send mail via VB,

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 1999
    Location
    mousafah,abu-dhabi,UAE
    Posts
    29
    hi VB programmers,
    i query about "how to send email by VB?"
    although, i download a lot of VB code, that can do so, but nothing works.
    PLZ, i will be glad if u give me addresses of good articles about how to send email
    BYE!
    Ahmed Walid

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Philadelphia
    Posts
    123
    The MSDN Library that comes w/ VB has pretty good documentation on how to send simple email. Here is code that I used to sign on to an Outlook Express account, write a simple email, attach a file, send the email, and sign off.

    First, you have to add a MAPISession and a MAPIMessage control to your form. To do this, add the Microsoft MAPI Controls, then add one of each control that is included. Then use my code to send the mail. I'm not sure how this will work w/ anything but Outlook Express, because I'm pretty new to VB myself....


    Code:
    mpsSession.SignOn    'Sign on to the default email account
    mpmMessage.SessionID = mpsSession.SessionID  'Link session and message
    mpmMessage.Compose   'Begin writing the email
    mpmMessage.RecipAddress = [email protected]  'Set the address to send to
    mpmMessage.AddressResolveUI = True  'Make sure the address exists
    mpmMessage.ResolveName
    mpmMessage.MsgSubject = "Some Subject"   'The subject of the email
    mpmMessage.MsgNoteText = "Some body"   'The body of the email
    mpmMessage.AttachmentPathName = "C:\MyAttachment"   'The name of the attachment
    mpmMessage.Send False   'Send w/out showing the email
    mpsSession.SignOff  'Sign off the account
    VB6 & VC++6 Pro (SP4), Java (Sun JDK)

  3. #3
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Here are two good examples:
    Tutorial
    and
    Demo Sendmail Project

    If you want to use OE then:
    Code:
    Private Sub Command1_Click()
    Dim oApp As Outlook.Application
    Dim oNameSpace As NameSpace
    Dim oFolder As MAPIFolder
    Dim oMailItem As Object
    Dim sMessage As String
    
    Set oApp = New Outlook.Application
    Set oNameSpace = oApp.GetNamespace("MAPI")
    Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox) 
    For Each oMailItem In oFolder.Items 
    With oMailItem 
    If oMailItem.Attachments.Count > 0 Then 
      oMailItem.Attachments.Item(1).SaveAsFile "C:\Temp\OutlookAttachments\" & _
      oMailItem.Attachments.Item(1).filename 
    End If
    MsgBox oMailItem.Attachments.Item(1).DisplayName & " was saved as " & _
    oMailItem.Attachments.Item(1).filename 
    End If 
    End With 
    Next oMailItem
    
    Set oMailItem = Nothing
    Set oFolder = Nothing
    Set oNameSpace = Nothing
    Set oApp = Nothing
    End Sub
    'Suplied by VB-Square Tips
    Hope that helps,
    D!m

    Dim

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