Email Method

Hi all

I’m having a small difficulty with a method that send an email. This method was first developed in 3.5 where it works flawlessly. After porting it over to 5.1 I can’t seem to get it to work. It keeps returning the error message “Confirmation Email Failed. Addresses Invalid”.

The 3.5 code is as follows:

var authorization = new Array('mail.smtp.host=mail.mw.centurytel.net', 'mail.smtp.auth=true', 'mail.smtp.port=587', 'mail.smtp.username=xxxxxx', 'mail.smtp.password=yyyyyy');

if (second_person_name)
{
	var secName = '\nSecond Name: ' + second_person_name
}
else
{
	secName = ' '
}

if (third_person_name)
{
	var thirdName = '\nSecond Name: ' + third_person_name
}
else
{
	thirdName = ' '
}

if (guest_sponsor == 'Sponsor')
{
	var name = '\nName: ' + second_person_name + thirdName
}
else
{
	name = '\nName: ' + display_full_name + secName
}

var sendAddA = reserve_to_nameƒidcode.email
var sendAddB = reserve_to_nameƒidcode.email_b
var fromAdd = 'wilderness@centurytel.net'
var subject = 'Reservation Confirmation'
var arr = utils.dateFormat(arrival_date, 'EEEEEE, MMMMM d, yyyy')
var dep = utils.dateFormat(departure_date, 'EEEEEE, MMMMM d, yyyy')
var can = utils.dateFormat(cancel_date_limit, 'EEEEEE, MMMMM d, yyyy')
var arrTime = arrival_time + ' ' + arrival_am
var depTime = departure_time + ' ' + departure_am
var fee = utils.numberFormat(cancel_fee, '¤#.00')

var bodyPart1 = 'Thank you for your recent reservation to The Wilderness Fellowship. We are pleased to confirm your reservation as follows:';
var bodyPart2 = 'We are eagerly awaiting your arrival and would like to advise you of the following in order to help you with your plans.';

var spec = 'Confirmation Number:  ' + reservation_number + '\nFacility:  ' + reserve_to_unitsƒcode.name + name + '\nArrival Date:  ' + arr + '\nArrival Time:  ' + arrTime + '\nDeparture Date:  ' + dep + '\nDeparture Time:  ' + depTime + '\nCancellation Date:  ' + can + '\nCancellation Fee:  ' + fee

if (unit_category_code == 'FC')
{
	var unitMsg = reserve_to_unitsƒcode.email_text
}
else
{
	unitMsg = reserve_to_unit_catƒcode.email_text
}

var msg = 'Dear ' + name_first + '\n\n' + bodyPart1 + '\n\n' + spec + '\n\n' + bodyPart2 + '\n\n' + unitMsg

if (sendAddB)
{
	var answer = plugins.dialogs.showInfoDialog( 'Choose Email Address',  'Ther are multiple email address available for this confimation.\n"Email Address A:  ' + sendAddA + '"\n"Email Address B:  ' + sendAddB + '"\nPlease choose which you want to use for this confimation.' , 'Email Address A', 'Email Address B')
	if (answer == 'Email Address A')
	{
		var sendAdd = sendAddA
	}
	else if (answer == 'Email Address B')
	{
		var sendAdd = sendAddB
	}
}
else
{
	var sendAdd = sendAddA
}

var success = plugins.mail.sendMail(sendAdd, fromAdd,  subject,  msg,null, null, null, authorization);
if (!success) 
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}

The 5.1 code looks like this(there are some obvious changes but the code is still basiclly the same.):

 function btn_Confirm_Reservation(event) {
	var authorization = new Array('mail.smtp.host=mail.mw.centurytel.net', 'mail.smpt.auth=true', 'mail.smtp.port=587', 'mail.smtp.username=xxxxxx', 'mail.smtp.password=yyyyyyy');
	if(reservation_second_name){
		var secName = '\nSecond Name: ' + reservation_second_name;
	}
	else{
		var secName = ' ';
	}
	if(reservation_third_name){
		var thirdName = '\nSecond name: ' + reservation_third_name;
	}
	else{
		var thirdName = ' ';
	}
	if(reservation_guest_spnosor == 'Sponsor'){
		var name = '\nName: ' + reservation_second_name + thirdName;
	}
	else{
		var name = '\nName: ' + display_full_name + secName;
	}
	var sendAdd1 = reserve_to_nameƒidcode.name_address_email_1;
	var sendAdd2 = reserve_to_nameƒidcode.name_address_email_2;
	var fromAdd = 'wilderness@centurytel.net';
	var subject = 'Reservation Confirmation';
	var arr = utils.dateFormat(reservation_arrive_date, 'EEEEEE, MMMMM d, yyyy');
	var dep = utils.dateFormat(reservation_depart_date, 'EEEEEE, MMMMM d, yyyy');
	var can = utils.dateFormat(reservation_cancel_limit, 'EEEEEE, MMMMM d, yyyy');
	var arrTime = reservation_arrive_time + ' ' + reservation_arrive_am;
	var depTime = reservation_depart_time + ' ' + reservation_depart_am;
	var fee = utils.numberFormat(reservation_cancel_fee, '¤#.00');
	
	var bodyPart1 = 'Thank you for your recent reservation to The Wilderness Fellowship. We are pleased to confirm your reservation as follows:';
	var bodyPart2 = 'We are eagerly awaiting your arrival and would like to advise you of the following in order to help you with your plans.';
	
	var spec = 'Confirmation Number:  ' + reservation_number + '\nFacility:  ' + reserve_to_unitsƒcode.unit_name + name + '\nArrival Date:  ' + arr + '\nArrival Time:  '
					+ arrTime + '\nDeparture Date:  ' + dep + '\nDeparture Time:  ' + depTime + '\nCancellation Date:  ' + can + '\nCancellation Fee:  ' + fee;
	if(reservation_unit_cat == 'FC'){
		var unitMsg = reserve_to_unitsƒcode.unit_email_text;
	}
	else{
		var unitMsg = reserve_to_unit_catƒcode.unit_category_email_text;
	}
	var msg = 'Dear ' + reservation_name_first + ',' + '\n\n' + bodyPart1 + '\n\n' + bodyPart2 + '\n\n' + unitMsg;
	if(sendAdd2){
		var answer = plugins.dialogs.showInfoDialog('Choose Email Address','There are multiple email addresses available for this confirmation.\n"Email Address A:  ' + sendAdd1 + 
			'\n"Email Address B:  ' + sendAdd2 + '\nPlease choose which you wish to use for this confirmation.','Email Address A','Email Address B','Both');
		if(answer == 'Email Address A'){
			var sendAdd = sendAdd1;
		}
		else if(answer == 'Email Address B'){
			var sendAdd = sendAdd2;
		}
		else if(answer == 'Both'){
			var sendAdd = sendAdd1 + ',' + sendAdd2;
		}
	}
	else{
		var sendAdd = sendAdd1;
	}
	var success = plugins.mail.sendMail(sendAdd, fromAdd,  subject,  msg, null, null, null, authorization);
	if(!success){
		var error = plugins.mail.getLastSendMailExceptionMsg();
		plugins.dialogs.showWarningDialog( 'Alert', 'Confirmation Email Failed.\n' + error, 'OK');
	}
}

All help is greatly appreciated.

MODERATOR: edited the username and password in the code.

if I was you I should edit your message, and replace your password with xxxxx ;-)
just my 2 cents…

but the error your are getting, is about the emailaddress you use.

do you use multiple emailaddresses? and what separator are you using? ; or , ?
please try both…

Oops My Bad.

Thanks for your Reply.

I checked all the addresses and they are correct. I confirmed this by running the same code in 3.5 with success.

So I wrote a test method with the addresses hard coded.

function test_Email(event) {
	var authorization = new Array('mail.smtp.host=mail.mw.centurytel.net', 'mail.smpt.auth=true', 'mail.smtp.port=587', 'mail.smtp.username=xxxxxxx', 'mail.smtp.password=xxxxxxx');
	var sendAdd = 'xxxxxx@sbcglobal.net';
	var fromAdd = 'xxxxxxx@centurytel.net';
	var subject = 'Test';
	var msg = 'This is a test.';
	var success = plugins.mail.sendMail(sendAdd, fromAdd,  subject,  msg, null, null, null, authorization);
	if(!success){
		var error = plugins.mail.getLastSendMailExceptionMsg();
		plugins.dialogs.showWarningDialog( 'Alert', 'Confirmation Email Failed.\n' + error, 'OK');
	}
}

It still returns the same error message.

do you see that same error on the server side in the server log?

What happens if you use the mail plugin from 3.5 in your 5.1 install?

Thanks Johan

jcompagner:
do you see that same error on the server side in the server log?

What happens if you use the mail plugin from 3.5 in your 5.1 install?

I copied the 3.5 mail plugin to the 5.1 and it still threw the same error message(minus the actual error description).

I’ve included the Server Log as well.

Exception in thread "main" java.lang.NoClassDefFoundError: com/servoy/j2db/server/ApplicationServer
Caused by: java.lang.ClassNotFoundException: com.servoy.j2db.server.ApplicationServer
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
Exception in thread "main" java.lang.NoClassDefFoundError: com/servoy/j2db/server/ApplicationServer
Caused by: java.lang.ClassNotFoundException: com.servoy.j2db.server.ApplicationServer
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
Exception in thread "main" java.lang.NoClassDefFoundError: com/servoy/j2db/server/ApplicationServer
Caused by: java.lang.ClassNotFoundException: com.servoy.j2db.server.ApplicationServer
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
Exception in thread "main" java.lang.NoClassDefFoundError: com/servoy/j2db/server/ApplicationServer
Caused by: java.lang.ClassNotFoundException: com.servoy.j2db.server.ApplicationServer
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
Exception in thread "main" java.lang.NoClassDefFoundError: com/servoy/j2db/server/ApplicationServer
Caused by: java.lang.ClassNotFoundException: com.servoy.j2db.server.ApplicationServer
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
Exception in thread "main" java.lang.NoClassDefFoundError: com/servoy/j2db/server/ApplicationServer
Caused by: java.lang.ClassNotFoundException: com.servoy.j2db.server.ApplicationServer
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)

Thanks for all your assistance.

that log is very weird,
You shouldnt even be able to startup the server because the core class ApplicationServer is not found
So i think that is not the log we want to see, because you did start the app server else you couldnt even start clients.

Sorry Johan

Try this one:

2010-03-23 11:26:42,273 ERROR [AWT-EventQueue-0] com.servoy.j2db.util.Debug - SMTPSend Invalid Addresses
javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
	com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 <tag7pro@sbcglobal.net>... Relaying denied: You must check for new mail before sending mail.

	at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1294)
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:635)
	at javax.mail.Transport.send0(Transport.java:189)
	at javax.mail.Transport.send(Transport.java:118)
	at com.servoy.extensions.plugins.mail.MailServer.sendMail(MailServer.java:300)
	at com.servoy.extensions.plugins.mail.MailProvider.js_sendMail(MailProvider.java:257)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:353)
	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3666)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2680)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:166)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3127)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:165)
	at com.servoy.j2db.scripting.Ztb.executeFunction(Ztb.java:120)
	at com.servoy.j2db.scripting.Zub.executeFunction(Zub.java:1)
	at com.servoy.j2db.Zub.Za(Zub.java:638)
	at com.servoy.j2db.Zub.Za(Zub.java:943)
	at com.servoy.j2db.Zac.Za(Zac.java:3)
	at com.servoy.j2db.ui.BaseEventExecutor.fireEventCommand(BaseEventExecutor.java:16)
	at com.servoy.j2db.ui.BaseEventExecutor.fireEventCommand(BaseEventExecutor.java:60)
	at com.servoy.j2db.ui.BaseEventExecutor.fireActionCommand(BaseEventExecutor.java:6)
	at com.servoy.j2db.dataui.Zab.actionPerformed(Zab.java:1)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
	at java.awt.Component.processMouseEvent(Component.java:6348)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
	at java.awt.Component.processEvent(Component.java:6113)
	at java.awt.Container.processEvent(Container.java:2085)
	at java.awt.Component.dispatchEventImpl(Component.java:4714)
	at java.awt.Container.dispatchEventImpl(Container.java:2143)
	at java.awt.Component.dispatchEvent(Component.java:4544)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
	at java.awt.Container.dispatchEventImpl(Container.java:2129)
	at java.awt.Window.dispatchEventImpl(Window.java:2475)
	at java.awt.Component.dispatchEvent(Component.java:4544)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 <tag7pro@sbcglobal.net>... Relaying denied: You must check for new mail before sending mail.

	at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1145)
	... 51 more

I hope this helps.

Relaying denied: You must check for new mail before sending mail.

so it seems that authentication with the smtp server you are using is not working
That smtp server expects that you pop/imap first before you can send an email.

If you say that you do login to that smtp server then something else is going wrong with the authentication.

Hi All

For the life of me I can not understand if some code works perfectly in 3.5 but not in 5.1 that there is something wrong outside Servoy, ie: authentication does not work. It would seem to me that if it works so well in 3.5 without any authentication problem, that, by all logic, it should work the same in 5.1. Maybe there is something different in the way that 5.1 handles the mail plugin that I don’t know about. After much testing on different machines, this anomaly is driving me batty.

Ok. So the error is “Relaying denied: You must check for new mail before sending mail.” Why is this a problem that only shows up in 5.1 and not in 3.5?

This is frustrating. Please Help!

if you now use that same method in a 3.5 install it works (so not it did work a couple of days ago in 3.5) but right now?

It could be that they changed the server authentication for example

I see you give this:

var authorization = new Array(‘mail.smtp.host=mail.mw.centurytel.net’, ‘mail.smpt.auth=true’, ‘mail.smtp.port=587’, ‘mail.smtp.username=xxxxxxx’, ‘mail.smtp.password=xxxxxxx’);

to the plugin, so it seems to me that that should still be used. Maybe something is changed that that doesnt work anymore so you could create a case
so that we can test that authentication our self.

But i am first curious if it really works right now in a 3.5 install.
Then what you could try is to use that mail plugin of a 3.5 install in a 5.1 install to see if it is something in the plugin.

Thanks for your help, Johan

jcompagner:
But i am first curious if it really works right now in a 3.5 install.

The 3.5 instance works correctly every time right now.

jcompagner:
Then what you could try is to use that mail plugin of a 3.5 install in a 5.1 install to see if it is something in the plugin.

I tried the 3.5 plugin in a 5.1 instance and it still did not work.
If I had your email I could send you an example from 3.5

make a case in our support system.
With the example and the data we need.