Announcement

Collapse
No announcement yet.

Send text file to email body--not as attachment?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Send text file to email body--not as attachment?

    I have searched for quite a while and can't seem to locate anywhere that explains how this is done. I want to take my weather warning text file from VWS and send it via email to my phone. I currently do that by sending the text file as an attachment but I want to see the text file in the body of the email. Anyone able to help a non programmer type?

    Stan

    #2
    Something like this perhaps, I don't use vws so not sure the format or location of the text file, this will send a text file in the root path called 'story.txt' (you will need to amend this to your vws text file location). The downside of this is that any formatting (line breaks) will be lost and there may be permissions issues if this script opens the text file and the plugin tries to open it aswell - but give it a go and see what happens.

    Code:
    Sub Main(ByVal Parms As Object)
    
    Dim fileReader As String
    
    fileReader = My.Computer.FileSystem.ReadAllText(hs.getapppath & "\story.txt")
    
    filereader = "This is a string from VWS: " & filereader
    
    hs.writelog("Email Send", filereader)
    
    hs.sendemail("toaddress@mail.com", "fromaddress@mail.com", "Subject", filereader)
    
    End Sub
    Save it as a .vb file in your scripts directory

    Comment


      #3
      Thanks mrhappy. Tried to run the script after substituting my parameters and get the following error.

      1/23/2011 12:16:37 PM - Error - Scripting runtime error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: The given path's format is not supported. at System.Security.Util.StringExpressionSet.CanonicalizePath(St ring path, Boolean needFullPath) at System.Security.Util.StringExpressionSet.CreateListFromExpre ssions(String[] str, Boolean needFullPath) at System.Security.Permissions.FileIOPermission.AddPathList(Fil eIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) at System.Security.Permissions.FileIOPermission..ctor(FileIOPer missionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) at System.IO.StreamReader..ctor(String path, Encoding encoding) at System.IO.File.ReadAllText(String path, Encoding encoding) at Microsoft.VisualBasic.MyServices.FileSystemProxy.ReadAllText (String file) at scriptcode1.scriptcode1.Main(Object Parms) --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)


      I substituted \story.txt with the path (c:\Program Files\HomeSeer HS2\DATA\VWS\1.txt). Also substituted the to/from email addresses.

      Have I done something wrong?

      Comment


        #4
        Originally posted by sbuckler View Post
        Thanks mrhappy. Tried to run the script after substituting my parameters and get the following error.

        1/23/2011 12:16:37 PM - Error - Scripting runtime error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: The given path's format is not supported. at System.Security.Util.StringExpressionSet.CanonicalizePath(St ring path, Boolean needFullPath) at System.Security.Util.StringExpressionSet.CreateListFromExpre ssions(String[] str, Boolean needFullPath) at System.Security.Permissions.FileIOPermission.AddPathList(Fil eIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) at System.Security.Permissions.FileIOPermission..ctor(FileIOPer missionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) at System.IO.StreamReader..ctor(String path, Encoding encoding) at System.IO.File.ReadAllText(String path, Encoding encoding) at Microsoft.VisualBasic.MyServices.FileSystemProxy.ReadAllText (String file) at scriptcode1.scriptcode1.Main(Object Parms) --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)


        I substituted \story.txt with the path (c:\Program Files\HomeSeer HS2\DATA\VWS\1.txt). Also substituted the to/from email addresses.

        Have I done something wrong?
        My fault, I should've been clearer, this line;

        ....hs.getapppath & "\story.txt")

        gets the root path of HomeSeer (so it does not matter if you are running HSPro or HS2 or you have it installed on another drive) and then adds \story.txt on the end, so in my case it would return C:\Program Files\HomeSeer HSPRO\story.txt

        in your case delete "\story.txt" and instead try "\DATA\VWS\1.txt" and see if it works, I think thats what the error you are seeing relates to.

        Comment


          #5
          Thanks mrhappy. Works like a charm! Appreciate your time and help.
          Stan

          Comment


            #6
            By the way, the formatting was fine on my Evo....just got a wind chill warning.

            Stan

            Comment


              #7
              nice to know thanks...I would'nt expect it to work with much more than a basic text file, if you need anything more sophisticated (images/marquees/text formatting) then you might be able to send HTML (I think it depends on how your phone decodes email though) but would need some additions to the code.

              Comment

              Working...
              X