CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: VB Emailing

  1. #1
    Join Date
    Apr 2001
    Location
    canada
    Posts
    11

    VB Emailing

    Hello. I am wondering how to go about emailing a long message in VB. I am using Outlook.application and such to do the actual mailing which works fine. But how do i go about sending a long message(30 lines long)? When I continue typing my message on the next line, it thinks it is more code. Do I use a '+' or '()'? None of those seem to work. I also must include contents of string variables in this message. I am sure this is easy, but I can't figure it out!! Please help!


  2. #2
    Join Date
    Aug 2001
    Location
    New York, USA
    Posts
    169

    Re: VB Emailing

    well, you can either use CDO library or MAPISession/MAPIMessage components. I have done some email functions in VB 6 with both of them (with Outlook and POP3/SMTP), but personally, I like CDO more than MAPI. I believe you can have more than 30 lines in a message.

    Is MultiLine turned on for the textbox?

    [email protected]


  3. #3
    Join Date
    Apr 2001
    Location
    canada
    Posts
    11

    Re: VB Emailing

    I am not sure what you mean by multiline. where can i turn it on? The problem is this:

    this is a test
    message

    "message" will be looked at by VB as another line of code separate from the line before it. How do I make it so that it will take roughly 30 lines of text and treat it as one line?


  4. #4
    Join Date
    Aug 2001
    Location
    New York, USA
    Posts
    169

    Re: VB Emailing

    do you have the code? I can take a look at the code.

    [email protected]


  5. #5
    Join Date
    Aug 2001
    Location
    New York, USA
    Posts
    169

    Re: VB Emailing

    here's an exmaple (no need to add CDO library and no MAPI components), but Outlook has to be open. you can just copy and paste the code into a Command button.


    dim strRecipient as string
    dim strMessage as string
    dim strSubject as string
    dim i as integer

    strRecipient = "Joe Smith" ' someone in your address book
    strSubject = "This is a test"

    'Create 32 lines of text
    for i = 0 to 32
    strMessage = strMessage & "This is line " & i & vblf
    next i


    'Create MAPI Session
    set objsession = CreateObject("MAPI.session")
    'logon to exchange server with default username
    objsession.logon "", "", false, false, 0
    'create message and recipient objects
    set objNewMessage = objsession.Outbox.Messages.Add
    set objRecipient = objNewMessage.Recipients.Add

    'pass names, subject and message to the objects
    objRecipient.Name = strRecipient
    objNewMessage.Subject = strSubject
    objNewMessage.Text = strMessage

    objRecipient.Resolve
    objNewMessage.Update
    objNewMessage.Send
    objsession.logoff


    try that.





  6. #6
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: VB Emailing

    Underscore is the line continuation character. Make sure that there is a space before the underscore and the last character on the line.

    strMessage = strMessage & "This is line " & i & vblf & _
    "This is another line" & _
    "This is still on the second line"


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

Featured