Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

send email on button click

hi guys

I am using Flex UI with java in the backend using spring Blazeds integration.

When i click on a flex button i need to submit an email with subject and some message body. If anyone has worked on such a requirment, I would greatly appreciate any help.

thanks.
Avatar of dgofman
dgofman
Flag of United States of America image

Try this solution
SmtpSocket.as
Avatar of Jay Roy

ASKER

let me look..thx

I have a button
<mx:Button click= what function should i call ? />

also, can you tell me what connection information i need to send the mail. I am working in a small company, for testing i can use my yahoo email, but i think eventually i will need the mail server information from my company?

thanks for help.
private function send():void{
      var smtp:SmtpSocket = new SmtpSocket();
      var Host:String = 'smtp.yourcompanydomain.com';
      var Username:String ='mail@yourcompanydomain.com';
      var Password:String = 'xxxxxxx';  
      var frmLbl:String = 'SMTP Mailer <mail@yourcompanydomain.com>';

      smtp = new SmtpSocket()
      smtp.Host = Host;
      smtp.Username =Username;
      smtp.Password = Password;
      smtp.frmLbl =frmLbl;
      smtp.Port = 25;
      smtp.connect(smtp.Host,      smtp.Port );
      smtp.recepient = "mail@yourcompanydomain.com";
      smtp.QuickSubject = "My Test";
      smtp.msgBody = "Hello World";
}
Avatar of Jay Roy

ASKER

great!

so if my company email is jay.ronda@benziga.com (company domain is benziga.com)

 var smtp:SmtpSocket = new SmtpSocket();
      var Host:String = 'smtp.benziga.com';
      var Username:String ='jay.ronda@benziga.com';
      var Password:String = 'xxxxxxx';  --my password
      var frmLbl:String = 'SMTP Mailer <jay.ronda@benziga.com>';  --is this right ?
      smtp = new SmtpSocket()
      smtp.Host = Host;
      smtp.Username =Username;
      smtp.Password = Password;
      smtp.frmLbl =frmLbl;
      smtp.Port = 25;  -- will this change for my company?    
      smtp.connect(smtp.Host,      smtp.Port );
      smtp.recepient = "jackie.oliver@benziga.com";  
      smtp.QuickSubject = "My Test";
      smtp.msgBody = "Hello World";
smtp.Port = 25;  -- will this change for my company?    
It's standard SMTP port number but you have to confirm with your System Administrator what SMTP port are you using.
Avatar of Jay Roy

ASKER

hi
In smtpsocket.as , i see this line

else if (code == "235") { //Authentication successful  
this.writeUTFBytes ("MAIL FROM: <devaraj@wp.pl>\r\n");

do you know what should i substitute devaraj@wp.pl  with ?

as i was suspecting , i am getting some port error
>>>
Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://localhost:9081/technoweb/techflex/main.swf cannot load data from smtp.benziga.com:25.
      
I cannot share my code I gave you example what I used 1 year ago. May be you need to download latest latest SMTPMailer.

http://www.bytearray.org/wp-content/projects/smtpmailer/SMTPMailer%200.6.zip
Avatar of Jay Roy

ASKER

no prob.
I down loaded smtpmailer from http://www.bytearray.org/wp-content/projects/smtpmailer/SMTPMailer%200.6.zip 

i see lot of .as files. smtpmailer.as , smtpevent.as , ect
so do you mean i need to replace smtpsocket.as with smtpmailer.as ?

thanks
No you can get latest project from Google

http://code.google.com/p/smtpmailer/downloads/detail?name=SMTPMailer 0.9.zip

or

http://code.google.com/p/as3maillib/


And find example or documentation on the internet

When I start working on SMTP client I used  SmtpSocket.as what I attached in my first email its small and very basic, but I modified for my server and added additional API's what may exists already in Open Source project.
Avatar of Jay Roy

ASKER

ok , got it. thanks
I am gonna talk to my admin and find the right smtp port, most problly thats the issue.

thx.
No problem, check what protocol you are using, if IMAP it may be hard to find exisitng code.
Avatar of Jay Roy

ASKER

we are using SMTP only, but there is most probably a firewall which is blocking me.
thx for all your help.
You may need to use SSH or VPN in this case also verify if you are using SMTP\SSL connection.
SOLUTION
Avatar of Suraj_Mathew
Suraj_Mathew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay Roy

ASKER

thx suraj.

dgofman, have a question. spoke to my admin, he says keep the port  empty , if doesnt work use the port 25 and use this server  NJWEBX2408.msad.benziga.com

I am trying without port first,so my new configuration is

var smtp:SmtpSocket = new SmtpSocket();
      var Host:String = 'smtp.NJWEBX2408.msad.benziga.com';
      var Username:String ='jay.ronda@benziga.com';
      var Password:String = 'xxxxxxx';  --my password
      var frmLbl:String = 'SMTP Mailer <jay.ronda@benziga.com>';  
      smtp = new SmtpSocket()
      smtp.Host = Host;
      smtp.Username =Username;
      smtp.Password = Password;
      smtp.frmLbl =frmLbl;
     // smtp.Port = 25;    //comment out
      smtp.connect(smtp.Host, smtp.Port );  //do you know what should this be?connect function //doesnt take one parameter      
      smtp.recepient = "jackie.oliver@benziga.com";  
      smtp.QuickSubject = "My Test";
      smtp.msgBody = "Hello World";

thanks
Sorry, is he junior admin?
You cannot connect to any host without port configuration.
Some are default for example when you are login to any web site you are using port 80
if you are login to bank application using HTTPS its port 443
SSH - 22
Telnet - 23
SMTP - 25
POP3 -110

So, I cannot understand his answer, ask somebody else.
Avatar of Jay Roy

ASKER

>>Sorry, is he junior admin?
heee, yes. i put the question through senior managment though and response received

you are trying to send email directly from flex to the SMTP server because of which browser is connecting directly to the SMTP server and is running into issues. Its better to send the email from the java, so you have client(flex) --> java (send email)


any thoughts?
thanks

Ok,
in this case you have two choices

1) Use some public SMTP server such as GMAIL
2) Using Suraj_Mathew files you can write java servlet what will except your request parameters from Flex and send via internal SMTP server.

Sorry,
David

Avatar of Jay Roy

ASKER

yeah.

suraj, in your actual Sendmail.java class is there a way to figure out if the mail has been sucessfully sent ?

if(email sucessfull){
do something
}
else{
do something else
}

is that possible?
right now i see Transport.send(simpleMessage); which is probalby sending the email but i want to check the sucess.

thanks guys.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay Roy

ASKER

works , thanks