Page 1 of 1

Scheduled Emails with Data Loggers Attachments

Posted: Tue Aug 06, 2013 1:48 am
by Sarah
Hi,

I am fairly new to scripting and would really appreciate all the help I can get to tackle this challenge.

I have a scheduler set up to export a range of data log and alarm server files daily to 'project files folder' in the panel. The exported files do not overwrite.

After the scheduler exports it to the project files folder, I need an email script to immediately send these exported files to one or more email addresses.

I have looked at the Script_Email sample, but I am not sure how to go about modifying it to perform the above.

Thanks

Re: Scheduled Emails with Data Loggers Attachments

Posted: Tue Aug 06, 2013 8:25 am
by mark.monroe
Unfortunately we do not have the resources to customize scripts for specific customers. The Script_Email has all the functions that you would need to attach a document to an email. In the "Alarm Distributor"->"Configure Distribution Devices" you configure the email server that relays the message.

Re: Scheduled Emails with Data Loggers Attachments

Posted: Tue Aug 06, 2013 8:06 pm
by Sarah
No worries Mark.

I'll need some help with a few basics and then hopefully I can work my way through this.

To add an attachment and specify its path, what syntax would I use?

Re: Scheduled Emails with Data Loggers Attachments

Posted: Wed Aug 07, 2013 7:53 am
by mark.monroe
Hi Sarah,

The example has how to add a file to an email. It is programmed on screen1. In the lower left hand corner of the screen is text that says "Script". Click on that it it will show you the code to create an email.
Snap 2013-08-07 at 07.51.59.jpg
Snap 2013-08-07 at 07.51.59.jpg (149.09 KiB) Viewed 17656 times
There are many posts on this forum on file paths and where files are located.

Re: Scheduled Emails with Data Loggers Attachments

Posted: Wed Aug 07, 2013 7:53 pm
by Sarah
Sorry Mark, it appears my question was too vague and was therefore misinterpreted.

But I have managed to get the email to add a specific attachment, so that's one step forward. In screen 1, I used the following (modifications shown in bold):

void SendButton_Click(System.Object sender, System.EventArgs e)
{
string filePath = "C://.../datalogger.xlsx";

string messageResult = Globals.MailScriptModule.SendEmail(RecieverTextBox.Text, SubjectTextBox.Text, BodyTextBox.Text, filePath);
MessageBox.Show(messageResult);
}

In the 'mail script module', I deleted the parts where it created an attachment and edited the line 'attachments.Add(attachment);'

However, the attachment gets renamed so that it includes the file location in it. I'm not sure why it's doing this. Any ideas?

Re: Scheduled Emails with Data Loggers Attachments

Posted: Thu Aug 08, 2013 8:15 am
by mark.monroe
I think you just need to comment out one line of code and you can leave the rest the same. I am not sure why your file is being renamed.

I would leave the MailScriptModule the same and use the below code in the screen:

Code: Select all

namespace Neo.ApplicationFramework.Generated
{
	using System.Windows.Forms;
	using System;
	using System.Drawing;
	using Neo.ApplicationFramework.Tools;
	using Neo.ApplicationFramework.Common.Graphics.Logic;
	using Neo.ApplicationFramework.Controls;
	using Neo.ApplicationFramework.Interfaces;
	using System.IO;
    
    
	public partial class Screen1
	{
		void SendButton_Click(System.Object sender, System.EventArgs e)
		{
			// Create a dummy attachement to send with the mail.
			//string attachementPath = Globals.MailScriptModule.CreateAttachement();
string attachementPath = "C:\\...";
			// Call the script module with the recievers mail address, subject and message body.
			// The message result tells if things went good or bad.
			string messageResult = Globals.MailScriptModule.SendEmail(RecieverTextBox.Text, SubjectTextBox.Text, BodyTextBox.Text, attachementPath);
			// Display the message result.
			MessageBox.Show(messageResult);
		}
	}
}

Re: Scheduled Emails with Data Loggers Attachments

Posted: Sat Sep 28, 2013 11:39 am
by lawrenceelectrical
Hi all
I am having problems with getting the exact locations of where the files are stored.
I can get emailing to work but now need to know the exact path of where the datalogger files are stored can someone help?

Re: Scheduled Emails with Data Loggers Attachments

Posted: Tue Oct 01, 2013 8:04 am
by mark.monroe
On a WinCE unit the"\Flashdrive" is the unit's hard disk and a USB comes up as a "\Harddisk". You should search this forum for the terms and you will find lots of information on where files are located. Our PC units use the standard "c:" paths.

Re: Scheduled Emails with Data Loggers Attachments

Posted: Wed Nov 13, 2013 9:46 am
by lawrenceelectrical
mark.monroe wrote:On a WinCE unit the"\Flashdrive" is the unit's hard disk and a USB comes up as a "\Harddisk". You should search this forum for the terms and you will find lots of information on where files are located. Our PC units use the standard "c:" paths.

Please could you help one last time I have emailing working well now but want to schedule it to send date on a change of shift. I see no reference to running scripts from the Scheduler, it this possible to do this.

Re: Scheduled Emails with Data Loggers Attachments

Posted: Wed Nov 13, 2013 12:07 pm
by lawrenceelectrical
lawrenceelectrical wrote:
mark.monroe wrote:On a WinCE unit the"\Flashdrive" is the unit's hard disk and a USB comes up as a "\Harddisk". You should search this forum for the terms and you will find lots of information on where files are located. Our PC units use the standard "c:" paths.

Please could you help one last time I have emailing working well now but want to schedule it to send date on a change of shift. I see no reference to running scripts from the Scheduler, it this possible to do this.

Thanks Sorted that!!