I am getting issues while downloading png attachment from the eml file using qtp code.
Downloaded File is not correct attachment.
Below is the code.
' Define the path to your EML file
emlFilePath = "C:\path\to\your\email.eml"
' Create a File System Object
Set fso = CreateObject("Scripting.FileSystemObject")
' Check if the EML file exists
If fso.FileExists(emlFilePath) Then
' Open the EML file
Set emlFile = fso.OpenTextFile(emlFilePath, 1)
' Read the content of the EML file line by line
Do Until emlFile.AtEndOfStream
line = emlFile.ReadLine
' Check if the line contains an attachment
If InStr(1, line, "Content-Disposition: attachment;", vbTextCompare) > 0 Then
' Extract the attachment filename
attachmentFilename = Mid(line, InStrRev(line, "filename=") + 10)
' Remove quotes and any leading or trailing spaces
attachmentFilename = Replace(attachmentFilename, """", "")
attachmentFilename = Trim(attachmentFilename)
' Copy the attachment to a desired location
' For example, to copy it to the desktop
destinationPath = "C:\Users\<your_username>\Desktop\" & attachmentFilename
fso.CopyFile emlFilePath, destinationPath
' Exit the loop after copying the attachment
Exit Do
End If
Loop
' Close the EML file
emlFile.Close
Else
MsgBox "EML file not found: " & emlFilePath
End If
' Clean up
Set fso = Nothing
' Define the path to your EML file
emlFilePath = "C:\path\to\your\email.eml"
' Create a File System Object
Set fso = CreateObject("Scripting.FileSystemObject")
' Check if the EML file exists
If fso.FileExists(emlFilePath) Then
' Open the EML file
Set emlFile = fso.OpenTextFile(emlFilePath, 1)
' Read the content of the EML file line by line
Do Until emlFile.AtEndOfStream
line = emlFile.ReadLine
' Check if the line contains an attachment
If InStr(1, line, "Content-Disposition: attachment;", vbTextCompare) > 0 Then
' Extract the attachment filename
attachmentFilename = Mid(line, InStrRev(line, "filename=") + 10)
' Remove quotes and any leading or trailing spaces
attachmentFilename = Replace(attachmentFilename, """", "")
attachmentFilename = Trim(attachmentFilename)
' Copy the attachment to a desired location
' For example, to copy it to the desktop
destinationPath = "C:\Users\<your_username>\Desktop\" & attachmentFilename
fso.CopyFile emlFilePath, destinationPath
' Exit the loop after copying the attachment
Exit Do
End If
Loop
' Close the EML file
emlFile.Close
Else
MsgBox "EML file not found: " & emlFilePath
End If
' Clean up
Set fso = Nothing
Try this code but code is not working. Expected to get eml file attachment to saved in folder