Micro Focus QTP (UFT) Forums
fucntion to send mail in outlook works fine in qtpcode but does not work in .vbs - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Others (https://www.learnqtp.com/forums/Forum-UFT-QTP-Others)
+--- Thread: fucntion to send mail in outlook works fine in qtpcode but does not work in .vbs (/Thread-fucntion-to-send-mail-in-outlook-works-fine-in-qtpcode-but-does-not-work-in-vbs)



fucntion to send mail in outlook works fine in qtpcode but does not work in .vbs - Rashmi - 08-13-2008

Hi ,

The following function works fine in QTP but when i paste it in .vbs file it throws mismatch error and says the .vbs file has syntax errors.
How to run .vbs file
Code:
Public Function SendMail(SendTo,SendCC,Subject,Body,Attachment)
    Dim olApp
    Dim olNs
    Dim olMail
    Set olApp = GetObject(, "Outlook.Application")
    On Error GoTo 0
    Set olMail = olApp.CreateItem(olMailItem)
    With olMail
        .To = SendTo
        .CC = SendCC
        .Subject = Subject
        .Body = Body
        .Attachments.Add(Attachment)
        .Display
    .Send
    End With
    Set olMail = Nothing
    Set olApp = Nothing
End Function



RE: fucntion to send mail in outlook works fine in qtpcode but does not work in .vbs - ashokghali - 08-22-2008

Hi,

Use the below function it works fine...

Code:
Function SendMail(SendTo, SendCC ,Subject, Body, Attachment)
Set ol =CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to=SendTo
mail.cc = SendCC
Mail.Subject=Subject
Mail.Body=Body
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If
Mail.Send
ol.Quit
Set Mail = Nothing
Set ol = Nothing
End Function


Thanks
-Ashok


RE: fucntion to send mail in outlook works fine in qtpcode but does not work in .vbs - byzoor - 06-13-2011

Hi,

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  Dim strSubject As String
  strSubject = Item.Subject
  If Len(strSubject) = 0 Then
      Prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
      If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
              Cancel = True
      End If
  End If
End Sub
Sub GetFormPassword()
    Dim objApp As Application
    Dim objInsp As Inspector
    Dim objFD As FormDescription


    Set objApp = CreateObject("Outlook.Application")
  
    Set objInsp = objApp.ActiveInspector
    If Not objInsp Is Nothing Then
        Set objFD = objInsp.CurrentItem.FormDescription

        MsgBox _
          Prompt:="The password for the " & _
                  Chr(34) & objFD.MessageClass & _
                  Chr(34) & " form is:" & _
                  vbCrLf & vbCrLf & objFD.Password, _
          Title:="Get Form Password"


    Else

        MsgBox _
          Prompt:="Please open an item using " & _
                  "the desired form before you " & _
                  "run the GetFormPassword macro.", _
          Title:="Get Form Password"

    End If
End Sub
Private Sub Application_NewMail()
    
    Dim m As MailItem
    Dim f As MAPIFolder
    Dim a As Attachment
    Set m = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items.GetLast
    Debug.Print m.Subject
    For Each a In m.Attachments
        a.SaveAsFile "C:\Documents and Settings\206954\My Documents\Mails\Attachments\" & a.DisplayName
    Next
    
End Sub

Code:
Function TestSendMail(SendTo,Subject, Body, Attachment)

   Set ol=CreateObject("Outlook.Application")
   Set Mail=ol.CreateItem(0)
   Mail.to=SendTo

   Mail.Subject=Subject
   Mail.Body=Body
   If (Attachment <> "") Then
       Mail.Attachments.Add(Attachment)
   End If
   Mail.Send

   ol.Quit

   Set Mail = Nothing
   Set ol = Nothing
End Function



Or


Happy Tester,
Byzoor,
9597711082