Render and Email script Problem

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
BigMacGyver
Posts: 19
Joined: May 7th, 2013, 6:43 am

August 21st, 2013, 7:22 am

Hello,

i am having a weird issue when trying to customize the functionality of the default Render and Email script that ships with AE.

when i want to run this script file directly from within another script, say by clicking a button:

Code: Select all

StartRender.onClick = function () {
                
                try{
                var RenderScript = new File("Macintosh HD/Applications/Adobe After Effects CS5.5/Scripts/Render and Email.jsx");
                alert(RenderScript.exists);
                RenderScript.open("r");
                eval(RenderScript.read());
                RenderScript.close();
                alert("done");
                }catch(e){alert("Problem.\n" + e.toString());
                
                }
            }
.exists returns true, so the file is being found. However, the javascript debugger will pop up the render and email.jsx saying "EmailSocket does not have a constructor". I tried various other things, including copying the entire render and email script into my own script file... which just gives me the same error when i run the function containing the email socket. So far, the only working option to run this script without getting an error is running it from the Run Script option within after effects. If i do so, i am receiving an email after rendering is done, so my settings i put into change email settings.jsx are correct. But now i am lost, because how can i implement the function of emailing upon render done? There is hardly any information about this and especially the code within the email_methods.jsx is like chinese to me, but apparently the "error" might be somewhere in there. Because writing a simple script that just sends an email directly using the email_methods.jsx returns similar error messages.

Hope someone can help me here.

btw, what am i actually trying to do: a customized render notifier that can notify several people at once about different, selectable aspects of a render progress. This needs to be implemented in my post production tools script.

Maybe a good starting point would be if i could find some kind of a small script that actually just sends an email with fixed specs when something happens (click of a button, for instance).

edit: and here just another example.

Code: Select all

var scriptName = "Render and Email";
var settings = app.settings;

var emailCodeFile = new File("(support)/email_methods.jsx");
			emailCodeFile.open("r");
			eval(emailCodeFile.read());
			emailCodeFile.close();
            
            var myMessage = "Hello.\r\n\r\n";

try {
					// Send the email.
					var serverSetting = settings.getSetting("Email Settings", "Mail Server");
					var fromSetting = settings.getSetting("Email Settings", "Reply-to Address");
					var toSetting = settings.getSetting("Email Settings", "Render Report Recipient");
					var authUser;
					var authPass;
					
					if (app.settings.haveSetting("Email Settings", "Auth User")) {
						authUser = app.settings.getSetting("Email Settings", "Auth User");
					}
					
					if (app.settings.haveSetting("Email Settings", "Auth Pass")) {
						authPass = app.settings.getSetting("Email Settings", "Auth Pass");
					}
					
					// Ack, can't delete settings...
					if (authUser == "") {
						authUser = null;
						authPass = null;
					}
					
					var myMail = new EmailSocket(serverSetting);
					
					if (!myMail.send(fromSetting, toSetting, "AE Render Completed", myMessage, authUser, authPass)) {
						alert("Sending mail failed.", scriptName);
					}
				} catch (e) {
					alert("Unable to send email.\n" + e.toString(), scriptName);
				}
This one will also give me an error saying EmailSocket does not have a constructor.
beginUndoGroup
Posts: 80
Joined: November 27th, 2012, 6:41 am

August 22nd, 2013, 2:05 am

Your script evals Render and Email.jsx which in turns evals email_methods.jsx, and the EmailSocket contructor is in that third script.
So apparently email_methods.jsx is not evaluated properly.

It is maybe because of the partial path: var emailCodeFile = new File("(support)/email_methods.jsx"); inside Render and Email.jsx.
It might work if you replace the partial path to full path as you did for Render and Email.jsx in your main script.
BigMacGyver
Posts: 19
Joined: May 7th, 2013, 6:43 am

August 22nd, 2013, 4:02 am

I tried this now, changed the path for email_methods.jsx in the Render and Email script, named it Render and Email2 and ran it by clicking the button in my main script. Now the java script debugger opens the email_methods.jsx, highlights line 122 and says: "Object of type Function found were a number, array or property is needed"

Here is the line 122 of code that is causing the error:

Code: Select all

this.writecrlfln(key + ": " + this.headers[key]);
The comment in Line 117 above states: // Send subject and time stamp

When i run the modified Render and Email2.jsx without the button click from the Toolkit directly, i get the same error as a message popup.

When i run the modified Render and Email2.jsx by Run Script from after effects, i get the constructor error again.

However, when i run the original contained under file/scripts/Render and Email.jsx everything works? I don't see the reason why my other versions would fail really. Nothing is different from the original except the script file name, the script location on the HD and the file locations within the script.

I might have to play around more with this, but maybe if someone has another idea it would be a real help.
BigMacGyver
Posts: 19
Joined: May 7th, 2013, 6:43 am

August 22nd, 2013, 4:14 am

Okay, a little update:

When restarting AE and running the following code:

Code: Select all

try{
                var RenderScript = new File("Macintosh HD/Applications/Adobe After Effects CS5.5/Scripts/ScriptUI Panels/Render and Email2.jsx");
                alert(RenderScript.exists);
                RenderScript.open("r");
                eval(RenderScript.read());
                RenderScript.close();
                alert("done");
                }catch(e){alert("Problem.\n" + e.toString());
                
                }
which runs the modified Render and Email2 file, everything works. So the error must be related to the way the button onClick calls the function, or possibly a global variable in my main script that might interfere with something further down the line. Is that possible?
BigMacGyver
Posts: 19
Joined: May 7th, 2013, 6:43 am

August 22nd, 2013, 6:07 am

So i have tracked the problem down by removing portions of my main script and keeping a very simple form of the render and email script that just sends a test message when a button gets clicked. It seems the problem is caused by the following code within the body of the main script:

Code: Select all

if (!Array.prototype.indexOf){
         
         Array.prototype.indexOf = function(searchElement /*, fromIndex */){
             
             "use strict";
             
             if (this === void 0 || this === null)
             throw new TypeError();
             
             var t = Object(this);
             var len = t.length >>> 0;
             if (len === 0)
             return -1;
             
             var n = 0;
             if (arguments.length > 0){
                 
                 n = Number(arguments[1]);
                 if (n !== n)
                 n = 0;
                 else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
                 n = (n > 0 || -1) * Math.floor(Math.abs(n));
                 }
             if (n >= len)
             return -1;
             var k = n >= 0
             ? n
             : Math.max(len - Math.abs(n), 0);
             
             for (; k < len; k++){
                 if (k in t && t[k] === searchElement)
                 return k;
                 }
             return -1;
             };
         }
It's a workaround for the missing indexOf method. I might just find a different solution for this one. However, i still do not see how this interfered with the email_methods.jsx. Can somebody maybe educate me on this?
BigMacGyver
Posts: 19
Joined: May 7th, 2013, 6:43 am

August 22nd, 2013, 7:43 am

So i managed something that works. Here is my advice if you get any of the following errors when using either email_methods.jsx, render and email.jsx or a variation of these within the body of a bigger script:
EmailSocket does not have a constructor
Object of type Function found were a number, array or property is needed
Make sure you check the body of your main script for functions that might be interfering with email_methods.jsx and possibly find a replacement/workaround for these functions. Hope this will help others who are confronted with this issue.
User avatar
chrisorcfilm
Posts: 1
Joined: October 7th, 2018, 5:54 pm

October 7th, 2018, 6:13 pm

Thank you for posting this! I've been beating my head against the wall.

For me, I was getting the dreaded "Unable to send email" error until I realized the script was hard coding port 25 in email_methods.jsx

When I repaired that to be port 587 I started getting the dreaded: "Unable to send email. Error: Object of type function found where a Number ... is needed"
until I realized that it was also occurring on email_methods.jsx at:

for (key in this.headers) {
this.writecrlfln(key + ": " + this.headers[key]);
}

The header array had been created but was empty and didn't seem to be being used anywhere else so I commented it out:

//for (key in this.headers) {
// this.writecrlfln(key + ": " + this.headers[key]);
//}

And Voila! Emails started working with AE's Render and Email.jsx

My only problem now is it is sending out emails with a timestamp of Coordinated Universal Time UTC so 7 hrs earlier than Pacific Time. Emails got lost in my inbox.

Any idea how to compensate the server time using the JavaScript Email Socket?

Thanks in Advance!
Post Reply