Email Plugin: Subject Line

Post Reply
Message
Author
JohnneyBoy
Posts: 147
Joined: Thu Aug 18, 2011 8:04 am

Email Plugin: Subject Line

#1 Post by JohnneyBoy » Sat Apr 21, 2012 2:53 am

Hello,

It would be of great use if it was possible to have the subject line definable on each message.

I can see from the code, this seems a tad difficult, as there is only parameter 1 and 2. I thought I had would be to delimit the subject at the beginning of either of these, i.e.

[This is the Subject Line]
or
:This is the Subject Line:

followed by either the email addresses or message, depending on which parameter used.

I realize this would need programing, which I'm happy to create, however which parameter do we prefer? :roll:

John

JohnneyBoy
Posts: 147
Joined: Thu Aug 18, 2011 8:04 am

Re: Email Plugin: Subject Line

#2 Post by JohnneyBoy » Sat Apr 21, 2012 7:33 am

OK.. so [ do not work.. scripting engine! opps... so I have written and tested some code using : colons, works fine.

Not sure if it's of interest to anyone, or where I can dump it...

John

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Email Plugin: Subject Line

#3 Post by Automate » Sat Apr 21, 2012 8:55 am

For small changes you can post a patch file in the forum.

Assuming you are using TortoiseSVN:
Right click the changed file then select "TortoiseSVN" then "Create patch..."
Click OK to accept the selected file
In the "Save as" popup click the "Save to clipboard" button
Then paste into a code block in a forum post.

nacker90
Posts: 5
Joined: Sat Mar 03, 2012 7:19 pm

Re: Email Plugin: Subject Line

#4 Post by nacker90 » Sun Apr 22, 2012 9:49 am

Why not just add a new parameter for the subject line?

JohnneyBoy
Posts: 147
Joined: Thu Aug 18, 2011 8:04 am

Re: Email Plugin: Subject Line

#5 Post by JohnneyBoy » Sun Apr 22, 2012 11:26 pm

Hello,

I did not want to change the major functionality of the existing plugin.

I'm not even sure extra params can be added, I have not noticed param3 on any of the existing forms.

If an extra param is possible, I would still think there would need to be a option on the plugin to enable/allow this method of operation, as complication of field delimitation could occur as commas are/can be used in normal message bodys.

thus parm1 = emailaddress
param2 = subject
param3 = body

(If possible)

Regards John

JohnneyBoy
Posts: 147
Joined: Thu Aug 18, 2011 8:04 am

Re: Email Plugin: Subject Line

#6 Post by JohnneyBoy » Mon Apr 23, 2012 5:33 am

Hello, Here is my modified code to allow subject line. Please note the delimiter is ':' a colon for the subject, and must start at the beginning of parameter 2, i.e. some@here.postfix,:Subject:bodytext

Code: Select all

Index: Email.cs
===================================================================
--- Email.cs	(revision 668)
+++ Email.cs	(working copy)
@@ -22,6 +22,9 @@
             try
             {
                 string to = "";
+                string parameter2 = "";
+                string subject = "";
+                string body = "";
                 ObjectProperty prop = osae.GetObjectPropertyValue(method.Parameter1, "Email Address");
                 if(prop != null)
                     to = prop.Value;
@@ -37,9 +40,36 @@
                 mailMsg.From = mailAddress;
 
                 // Subject and Body
-                mailMsg.Subject = "Message from OSAE";
-                mailMsg.Body = osae.PatternParse(method.Parameter2);
+                parameter2 = osae.PatternParse(method.Parameter2);
 
+                // Make sure there is a body of text.
+                if (parameter2.Equals(""))
+                    throw new ArgumentOutOfRangeException("Message body missing.");
+
+                // See if there is a subject.
+                // Opening delimiter in first char is good indication of subject.
+                if (parameter2[0] == ':')
+                {
+                    // Find clossing delimiter
+                    int i = parameter2.IndexOf(':', 1);
+                    if (i != -1)
+                    {
+                        subject = parameter2.Substring(1, i - 1);
+                        body = parameter2.Substring(i + 1, parameter2.Length - i - 1);
+                    }
+                }
+
+                if (subject.Equals(""))
+                {
+                    mailMsg.Subject = "Message from OSAE";
+                    mailMsg.Body = parameter2;
+                }
+                else
+                {
+                    mailMsg.Subject = subject;
+                    mailMsg.Body = body;
+                }              
+
                 // Init SmtpClient and send
                 SmtpClient smtpClient = new SmtpClient(osae.GetObjectPropertyValue(pName, "SMTP Server").Value, Int32.Parse(osae.GetObjectPropertyValue(pName, "SMTP Port").Value));
                 if (osae.GetObjectPropertyValue(pName, "ssl").Value == "TRUE")
Hope this is of use.

John

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Email Plugin: Subject Line

#7 Post by Automate » Mon Apr 23, 2012 6:23 am

nacker90 wrote:Why not just add a new parameter for the subject line?
Allowing OSA plugins to use a third parameter for methods would require at least the following changes, maybe more
Modify database tables to hold a 3rd parameter
Modify stored procedures to use the 3rd parameter
Modify the OSA API to use the 3rd parameter
Modify the script processor to look for a 3rd parameter
Modify GUI to allow entry of a 3rd parameter

User avatar
bwoodworth
Site Admin
Posts: 1563
Joined: Tue May 04, 2010 6:49 am
Location: California

Re: Email Plugin: Subject Line

#8 Post by bwoodworth » Mon Apr 23, 2012 1:42 pm

I will add this into the code. Thanks for the contribution.
Brian

Post Reply