How to send Mail with attachment

Good Day!

In my current project I am using web harvest mail tag to send a mail with attachment(.xlsx/.pdf). whenever we attach some attachment, we can receive only a file format.

Can you please guide me in getting correct file format.

  <mail smtp-host="mail.xxxx.xx.xx"
      smtp-port="25"
      type="html"
      from="kathirvel.balasubramaniam@xxxx.xx.xx"
      reply-to="kathirvel.balasubramaniam@xxxx.xx.xx"
      to="kathirvel.balasubramaniam@xxxx.xx.xx"
      subject="Test"
      charset="UTF-8"
      security="tsl">
   
      HI, i am just testing email process
    <mail-attach name="VAF" mimetype="application/octet-stream">
      <file path="C:/Users/C738624/Desktop/VAF.xml" type="binary"/>
    </mail-attach>
</mail>
1 Like

@aharhots

Here is a working example:

        <?xml version="1.0" encoding="UTF-8"?>
        <config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config">

        	<mail smtp-host="smtp.something.com" 
              smtp-port="465" 
              type="html"
              from="you@something.com"
              to="your_friend@other.com"
              subject="mail-test-plugin"
              charset="UTF-8"
              username="your_email@something.com"
              password="your_password"
              security="ssl">
              
            	mail content  
            
            <mail-attach name="application.pdf" mimetype="application/octet-stream">
              <file path="c:\Users\azinchuk\Downloads\application.pdf" type="binary"/>
            </mail-attach>

     <!-- Or use relative URL (from your configs folder):  -->

            <mail-attach name="input.csv" mimetype="application/octet-stream">
              <file path="..\input\input_data_file.csv" type="binary"/>
            </mail-attach>
         	
           </mail>
         	
            <export include-original-data="true"></export>
            
        </config>
3 Likes

Thank you tested and working… Appreciated

I have a scenario to attach a file to a mail which we are sending via plugin in WF (reference takne from this forum post: https://forum.workfusion.com/t/how-to-send-mail-with-attachment/351)

What I am doing is creating a file in the WF server and then give that file location to the “File plugin” using “path” attribute, similar to below code snippet, and then deleting the file from the file system.

My questions are:

  1. Is this a correct approach to do this, considering we will be creating a file in the file system of WF server? If not please explain the correct way of doing this.

  2. Is it possible to provide a URI ( e.g: S3 location) to the “path” attribute of the “file” plugin?

@hhtdthilakarathne,

The file needs to be located on WF server if you are executing the bot task from the Control Tower web application.

The given example has local path because it is a training example and it is executed from WF Studio on a local machine.

You can attach any binary data - see https://kb.workfusion.com/display/WF/Standard+Web-Harvest+processors#StandardWeb-Harvestprocessors-mail-attach

If you want to download a file via http, you can use the following code:

<file action="write" path="123.txt">
    <http-extended url="https://s3-file-link" method="GET" content-type="application/json">
</file>
1 Like

Thank you for the reply. I am using the control tower web application. Is there a specific directory within the WorkFusion server which we can use to download these temporary files to? Or is it okay if the file path is set to any directory we wish?

@hhtdthilakarathne,

it is better to use the /tmp folder. But do not forget to clean this folder on a regular basis.

I am trying to send mail with attachment .I am getting “Error reading file: C:/download.jpg”.Though file exists in this path the error is mentioned as file doesn’t not exists.Can you please help me to resolve this issue.

Hi @azinchuk ,

I am trying to use this script on my code but i get some error.

Error:

Error executing CustomScriptAction
  com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=CustomScriptAction.ftl,id=1,name=Optional[CustomScriptAction],parent=-1,arguments=ActionArguments[delay=[0],timeoutMs=[10000],xsi:type=[recorder:CustomScriptAction, recorder:CustomScriptAction],pollingInterval=[300],active=[true],script=[ <?xml version="1.0" encoding="UTF-8"?>
        <config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config">

        	<mail smtp-host="smtp.ngl.corp" 
              smtp-port="25" 
              type="html"
              from="Noreply_bot@*********.com"
              to="jcuencca@everis.com"
              subject="Test script"
              charset="UTF-8"
              username="*****"
              password="**********"
              security="ssl">
              
            	mail content  
            
            <mail-attach name="a.png" mimetype="application/octet-stream">
              <file path="C:\Users\druizvar\Desktop\a.png" type="binary"/>
            </mail-attach>
         	
           </mail>
         	
            <export include-original-data="true"></export>
            
        </config>],awaitTimeout=[5000]]]
      at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:54)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
      at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: com.google.common.util.concurrent.UncheckedExecutionException: com.workfusion.studio.rpa.recorder.utils.CustomActionCompilationFailedException: startup failed:
methodSource: 1: unexpected token: < @ line 1, column 2.
    <?xml version="1.0" encoding="UTF-8"?>
    ^

1 error

      at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2199)
      at com.google.common.cache.LocalCache.get(LocalCache.java:3932)
      at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936)
      at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806)
      at com.workfusion.studio.rpa.recorder.freemarker.method.ExtractCustomActionNameMethod.exec(ExtractCustomActionNameMethod.java:45)
      at freemarker.core.MethodCall._eval(MethodCall.java:62)
      at freemarker.core.Expression.eval(Expression.java:78)
      at freemarker.core.Assignment.accept(Assignment.java:131)
      at freemarker.core.Environment.visit(Environment.java:324)
      at freemarker.core.MixedContent.accept(MixedContent.java:54)
      at freemarker.core.Environment.visit(Environment.java:324)
      at freemarker.core.Environment.process(Environment.java:302)
      at freemarker.template.Template.process(Template.java:325)
      at com.workfusion.studio.rpa.recorder.freemarker.FreemarkerTemplateProcessor.process(FreemarkerTemplateProcessor.java:84)
      at com.workfusion.studio.rpa.recorder.playback.ActionTemplate.process(ActionTemplate.java:42)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.executeBehavior(TemplateAction.java:33)
      at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:46)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
      at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: com.workfusion.studio.rpa.recorder.utils.CustomActionCompilationFailedException: startup failed:
methodSource: 1: unexpected token: < @ line 1, column 2.
    <?xml version="1.0" encoding="UTF-8"?>
    ^

1 error

      at com.workfusion.studio.rpa.recorder.utils.CustomScriptActionParser.<init>(CustomScriptActionParser.java:31)
      at com.workfusion.studio.rpa.recorder.freemarker.method.ExtractCustomActionNameMethod$1.load(ExtractCustomActionNameMethod.java:32)
      at com.workfusion.studio.rpa.recorder.freemarker.method.ExtractCustomActionNameMethod$1.load(ExtractCustomActionNameMethod.java:28)
      at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3522)
      at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2315)
      at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2278)
      at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2193)
      at com.google.common.cache.LocalCache.get(LocalCache.java:3932)
      at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936)
      at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806)
      at com.workfusion.studio.rpa.recorder.freemarker.method.ExtractCustomActionNameMethod.exec(ExtractCustomActionNameMethod.java:45)
      at freemarker.core.MethodCall._eval(MethodCall.java:62)
      at freemarker.core.Expression.eval(Expression.java:78)
      at freemarker.core.Assignment.accept(Assignment.java:131)
      at freemarker.core.Environment.visit(Environment.java:324)
      at freemarker.core.MixedContent.accept(MixedContent.java:54)
      at freemarker.core.Environment.visit(Environment.java:324)
      at freemarker.core.Environment.process(Environment.java:302)
      at freemarker.template.Template.process(Template.java:325)
      at com.workfusion.studio.rpa.recorder.freemarker.FreemarkerTemplateProcessor.process(FreemarkerTemplateProcessor.java:84)
      at com.workfusion.studio.rpa.recorder.playback.ActionTemplate.process(ActionTemplate.java:42)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.executeBehavior(TemplateAction.java:33)
      at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:46)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
      at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
methodSource: 1: unexpected token: < @ line 1, column 2.
    <?xml version="1.0" encoding="UTF-8"?>
    ^

1 error

      at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:311)
      at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:108)
      at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
      at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:121)
      at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:133)
      at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:332)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:226)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:192)
      at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:230)
      at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:186)
      at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:968)
      at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:633)
      at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:609)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:586)
      at com.workfusion.studio.rpa.recorder.utils.CustomScriptActionParser.<init>(CustomScriptActionParser.java:29)
      at com.workfusion.studio.rpa.recorder.freemarker.method.ExtractCustomActionNameMethod$1.load(ExtractCustomActionNameMethod.java:32)
      at com.workfusion.studio.rpa.recorder.freemarker.method.ExtractCustomActionNameMethod$1.load(ExtractCustomActionNameMethod.java:28)
      at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3522)
      at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2315)
      at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2278)
      at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2193)
      at com.google.common.cache.LocalCache.get(LocalCache.java:3932)
      at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936)
      at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806)
      at com.workfusion.studio.rpa.recorder.freemarker.method.ExtractCustomActionNameMethod.exec(ExtractCustomActionNameMethod.java:45)
      at freemarker.core.MethodCall._eval(MethodCall.java:62)
      at freemarker.core.Expression.eval(Expression.java:78)
      at freemarker.core.Assignment.accept(Assignment.java:131)
      at freemarker.core.Environment.visit(Environment.java:324)
      at freemarker.core.MixedContent.accept(MixedContent.java:54)
      at freemarker.core.Environment.visit(Environment.java:324)
      at freemarker.core.Environment.process(Environment.java:302)
      at freemarker.template.Template.process(Template.java:325)
      at com.workfusion.studio.rpa.recorder.freemarker.FreemarkerTemplateProcessor.process(FreemarkerTemplateProcessor.java:84)
      at com.workfusion.studio.rpa.recorder.playback.ActionTemplate.process(ActionTemplate.java:42)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.executeBehavior(TemplateAction.java:33)
      at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:46)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
      at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
      at java.lang.Thread.run(Thread.java:745)

Code:

        <config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config">

        	<mail smtp-host="smtp.ngl.corp" 
              smtp-port="25" 
              type="html"
              from="Noreply_bot@******.com"
              to="jcuencca@everis.com"
              subject="Test script"
              charset="UTF-8"
              username="*********"
              password="************"
              security="ssl">
              
            	mail content  
            
            <mail-attach name="a.png" mimetype="application/octet-stream">
              <file path="C:\Users\druizvar\Desktop\a.png" type="binary"/>
            </mail-attach>
         	
           </mail>
         	
            <export include-original-data="true"></export>
            
        </config>

you cannot use this XML code inside the Recorder Custom Script action. You need to:

  1. Switch to the Code perspective
  2. Create a Bot Task
  3. Insert the code from the examples
  4. Run the bot task

Hi Team,

Can u please provide smtp settings for Outlook.

Smtp-host,smtp-port

Thanks

You can find them here https://support.office.com/en-us/article/pop-imap-and-smtp-settings-for-outlook-com-d088b986-291d-42b8-9564-9c414e2aa040