Email with VB
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 26

Thread: Email with VB

  1. #1
    Join Date
    May 2002
    Posts
    2

    Email with VB

    Can i send email through Visual Basic ?
    Thankx

  2. #2
    Join Date
    Aug 2001
    Posts
    1,447
    absolutely. Do a search --- there's a ton of stuff on it.

    also might want to look on planet source code for examples
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  3. #3
    Join Date
    Aug 2001
    Posts
    1,447
    here's something I saved off some time ago. Don't remember if I ever tried it:

    The simplest code to send emails is this: (need you have installed the Outlook

    Code:
    Dim objOutlook As Object
    Dim objOutlookMsg As Object
    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutlookMsg = objOutlook.CreateItem(0)
    With objOutlookMsg
    .To = "you@email.com
    .Cc = "ifneed@copy.com"
    .Subject = "Hello World (one more time)..."
    .Body = "This is the body of message"
    .HTMLBody = "HTML version of message"
    .Attachments.Add ("c:\myFileToSend.txt")
    .Send 'Letīs go!
    End With
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    [Colorized by Cimperiali for better reading]
    Last edited by Cimperiali; December 7th, 2002 at 04:29 AM.
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  4. #4
    Join Date
    Sep 2002
    Location
    ON-CA
    Posts
    6
    Why don't you just use the MAPI Controls (MAPISession and MAPIMessages)? That's what they are for -- to send and receive email.

    If you use the Outlook Express type libraries your app will only work on computers that have Outlook Express installed.

  5. #5
    Join Date
    Sep 2002
    Location
    Africa
    Posts
    147
    From somewhere in this forum

    Code:
    Private Sub cmdEmail_Click()
    
        MAPISession1.SignOn
        MAPIMessages1.SessionID = MAPISession1.SessionID
        MAPIMessages1.Compose
        MAPIMessages1.RecipAddress = "successtory@hotmail.com"
        MAPIMessages1.ResolveName
         
        MAPIMessages1.MsgSubject = "Message Subject"
        MAPIMessages1.MsgNoteText = "Hello World"
         
        MAPIMessages1.Send False
        MAPISession1.SignOff
    
    End Sub
    [Colorized by Cimperiali for better reading]
    Last edited by Cimperiali; December 7th, 2002 at 04:31 AM.

  6. #6
    Join Date
    Aug 2002
    Location
    Athens , Greece
    Posts
    151
    well this source code is impartial.
    what references does it need? i can nowhere find a MAPI dll.
    thanks

  7. #7
    Join Date
    May 2002
    Location
    Ukraine
    Posts
    228
    It is OCX control,
    find it (Microsoft Mapi controls), place to form and use
    as control.

    Originally posted by alexr123
    well this source code is impartial.
    what references does it need? i can nowhere find a MAPI dll.
    thanks

  8. #8
    Join Date
    Dec 2003
    Posts
    7
    Just wondering... That MAPI.send false line... Does that actually send it off? Kinda ironic that FALSE will actually do the sending

    EDIT:

    Okay I just tried it... And it appears that it does so in deed send But another problem arises... Outlook will prompt you if you want to send a message... Is there anyway to just use a SMTP server to send off a message?
    Last edited by Randuin; December 8th, 2003 at 11:05 PM.

  9. #9
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    651
    I don't know if this will help, but here's the SMTP code that I used:


    Code:
    Dim SMTP As ANSMTPLib.OBJ
        
        
        Set SMTP = New ANSMTPLib.OBJ
        SMTP.ServerAddr = "mail.server.com"
        SMTP.RegisterKey =   'Fill in your register key if you have one
        SMTP.FromAddr = "from@server.com"
        SMTP.ReplyTo = "replyto@server.com"
        SMTP.Subject = "Subject"
        SMTP.BodyFormat = 0 'Text Format [1=HTML]
        SMTP.BodyText = "Body"
        
        SMTP.AddRecipient "Recipient Name", "recipient@server.com", 0 
               
    
        If SMTP.SendMail() = 0 Then
            MsgBox "Message Sent!"
        Else
            MsgBox "Error Sending Message!" & vbCr & SMTP.GetLastError & ": " _
                    & SMTP.GetLastErrDescription
        End If
       
        Set SMTP = Nothing
    I'd rather be wakeboarding...

  10. #10
    Join Date
    Dec 2003
    Posts
    7
    What version of VB are you using and what extra namespace/controls did you reference to? I can't seem to define as an ANSMTPLib o.O

  11. #11
    Join Date
    Oct 2004
    Location
    Australia, Yeppoon
    Posts
    44

    Arrow Re: Email with VB

    Quote Originally Posted by Platinum Plus
    From somewhere in this forum

    Code:
    Private Sub cmdEmail_Click()
    
        MAPISession1.SignOn
        MAPIMessages1.SessionID = MAPISession1.SessionID
        MAPIMessages1.Compose
        MAPIMessages1.RecipAddress = "successtory@hotmail.com"
        MAPIMessages1.ResolveName
         
        MAPIMessages1.MsgSubject = "Message Subject"
        MAPIMessages1.MsgNoteText = "Hello World"
         
        MAPIMessages1.Send False
        MAPISession1.SignOff
    
    End Sub
    [Colorized by Cimperiali for better reading]
    Would somebody please be able to write details of each line of the above code. I do not understand what "resolvename" does.
    Also I need to know how to add over 1 attachment, being a noob and all I tried:
    MAPIMessages1.AttachmentPathName = "C:\hello.txt" & "C:\hello2.txt"
    but it dont work, and if 2 cases of AttachmentPathName is made it only sends the last attachment.
    Last edited by Bnoyzy; November 11th, 2004 at 06:02 AM.

  12. #12
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,853

    Re: Email with VB

    You can forget about MAPI and Outlook (unless you only want to sent a couple of emails)

    Microsoft have provided a popup message which forces you to confirm that you want to programatically control outlook via an external program. This means you need to keep clicking buttons for every email sent. (great if you like clicking)

    This feature came in when Microsoft lost the plot about how to control the likes of the "Luv Virus" etc. (Around Outlook 2002)

    You can always install Outlook 2000 to get around this feature. (or find a tricky bit of code which automatically provides a click for you - they do exist)

    The other alternative is to bypass all this by using SMTP - just watch out for the fact that SMTP will not keep a copy in Outlook's sent box as it does not use Outlook.

    Normally if you are automatically broadcasting lots of addresses with the same email, then you probably don't want a copy anyway.

    If you really do want a copy, then you could always automatically send yourself a copy of the email using the CC: or BCC: addresses

  13. #13
    Join Date
    Oct 2001
    Location
    Melbourne, Australia
    Posts
    576

    Re: Email with VB

    you need to increment attachmentindex:
    Code:
    MAPIMessages1.AttachmentIndex = .AttachmentIndex + 1
    MAPIMessages1.AttachmentPathName = Trim(adoFileType.Recordset!additionalAttach)
    BUT, I would suggest following everyone elses advice and ditch MAPI all together. It's on the out and has a number of issues and holes in it's functionality before you even get near the Outlook problems with having to confirm each send.

    do a search for "vbsendmail". it's a dll that you can call that does it all for you and is very good - and best of all, I think it is free! It's well documented and has far more features than mapi provides, and even if you have got 95% through your MAPI implementation, I would still suggest scrapping that and using something else (like VbSendMail).

  14. #14
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    Re: Email with VB

    maybe it's a good .dll but i need the code in it so that i can learn how to do stuff
    i can manage to send via outlook app..but like George1111 said..it's need to click a button to send an email..
    does anyone have a sample code that can be used to send email via anything that can send to every email server (yahoo, hotmail, etc)..coz it seems the code work for hotmail but not for yahoo..
    i've tried the FAQ's but it just work for the Outlook stuff..

    i'm not familiar with this before..so maybe it's like a dumb question
    regards

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

  15. #15
    Join Date
    Oct 2001
    Location
    Melbourne, Australia
    Posts
    576

    Re: Email with VB

    Erick - check this out:
    http://www.microsoft.com/technet/arc...oy/d5smtp.mspx

    get down to the bit about "Verifying the SMTP service" and see if that helps you.

    i'm trying to do this in .Net at the moment, and getting great success with internal addresses, but can't send externally, so trying to fix it I found this which may help you

    anyway, there are heaps of ways to send email. you can use Outlook, Mapi (which uses your client anyway), external dlls like the one I mentioned above, or you could even telnet to an smtp server and send the commands down that ("mail from: zeb@blah.blah.net", "rcpt to: erick@blah.blah.org", so on - i don't know them all).

    one bit in the article that was interesting is the "pickup directory". anyway, maybe it helps, maybe it doesn't. i guess it comes down to whether you guys use your own mail server or an ISP.

Page 1 of 2 12 LastLast

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center