none
vbscript for sending output of question by emails RRS feed

  • Question

  • Hi,

    I need a script that will have several questions , and i want to take the answers and send it by email(using outlook software) in the body and not with file attached .

    I got a script to the questions and answers , and i have the script of sending an email with outlook , i just dont know how to link the output to the body.

    here are the example i own (suggestions and adjustments will be welcomed):

    script for the mail :

       Set objOutlook = CreateObject("Outlook.Application")
       Set objMail = objOutlook.CreateItem(0)
       objMail.Display   'To display message
       objMail.Recipients.Add ("*****@****.**.**")
       objMail.Subject = "Mail Subject"
       objMail.Body = "This is Email Body"
       objMail.Send
       Set objMail = Nothing
       Set objOutlook = Nothing

    script 1 for q/a :

    Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNeeded = true
    set fso = CreateObject("Scripting.FileSystemObject")
    set file = fso.OpenTextFile("output.txt", ForAppending, CreateIfNeeded)

    dim fname
    fname = inputbox("Hi! What's your name?")
    dim fname2
    fname2 = inputbox("And what is your job ?")
    file.write fname
    file.write fname2
    file.close

    script2 for q/a :


      ' Input Box with a Title
      a=InputBox("question1","Enter Value")
      msgbox a
     
      ' Input Box with a Title
      a=InputBox("question2","Enter Value")
      msgbox a
     
      ' Input Box with a Title
      a=InputBox("question3","Enter Value")
      msgbox a
     
      ' Input Box with a Title
      a=InputBox("question4","Enter Value")
      msgbox a
     
      ' Input Box with a Title
      a=InputBox("question?","Enter Value")
      msgbox a


    Monday, June 2, 2014 6:30 AM

Answers

  • Here you go:

    'Input Box with a Title
    sText = InputBox("question1","Enter Value") & vbCrLf
     
    'Input Box with a Title
    sText = sText & InputBox("question2","Enter Value") & vbCrLf
    etc.

    Now put your E-Mail code here, including this line:

    objMail.Body = sText

    • Marked as answer by MagicMan007 Monday, June 2, 2014 9:34 AM
    Monday, June 2, 2014 8:28 AM

All replies

  • Here you go:

    'Input Box with a Title
    sText = InputBox("question1","Enter Value") & vbCrLf
     
    'Input Box with a Title
    sText = sText & InputBox("question2","Enter Value") & vbCrLf
    etc.

    Now put your E-Mail code here, including this line:

    objMail.Body = sText

    • Marked as answer by MagicMan007 Monday, June 2, 2014 9:34 AM
    Monday, June 2, 2014 8:28 AM
  • Thanks , you nailed it ! :)

    just one more addition as i advanced with the script , if i want to seperate the subject from the sText , how can it be done ?

    sText is going to the body and i want the lets say sText1 will go to the Subject - what is the correct way to do so ?

    Monday, June 2, 2014 9:36 AM