[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

flex 4 sending email + java attachment

Asked by aaronyeo22 in Adobe Flex, Java Programming Language

Tags: send email java + flex 4

i able to send the email go through via flex 4 (backend java). but i fail to send an attachment . Please. Help.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
java code
 
import java.util.Date;
import java.util.Properties;
 
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
 
 
public class Main {
 
   public  void sendMail(String toemail, String subject, String body, String messageBody,String[] file)
         throws MessagingException {
      String host = "mail.abc.com";
      String user = "info@abc.com";
      String pass = "abc";
      // Create properties, get Session
      Properties props = System.getProperties();
      props.put("mail.host", host);
      props.put("mail.transport.protocol.", "smtp");
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.", "true");
      props.put("mail.smtp.port", "2525");
      props.put("mail.smtp.socketFactory.fallback", "false");
      Session mailSession = Session.getDefaultInstance(props, null);
      Message msg = new MimeMessage(mailSession);
      msg.setFrom(new InternetAddress(user));
      InternetAddress[] address = { new InternetAddress(toemail) };
      msg.setRecipients(Message.RecipientType.TO, address);
      msg.setSubject(subject);
      msg.setSentDate(new Date());
      msg.setText(body);
      
      BodyPart messageBodyPart = new MimeBodyPart();
		messageBodyPart.setText(messageBody);
	
		Multipart multipart = new MimeMultipart();
		
		multipart.addBodyPart(messageBodyPart);
	
		addAtachments(file, multipart);
		
		msg.setContent(multipart);
      
      
      Transport transport = mailSession.getTransport("smtp");
      transport.connect(host, user, pass);
      transport.sendMessage(msg,msg.getAllRecipients());
      transport.close();
      
   }
   protected void addAtachments(String[] attachments, Multipart multipart)
	throws MessagingException, AddressException
	{
	for(int i = 0; i<= attachments.length -1; i++ )
	{
	String filename = attachments[i];
	MimeBodyPart attachmentBodyPart = new MimeBodyPart();
	
	DataSource source = new FileDataSource(filename);
	attachmentBodyPart.setDataHandler(new DataHandler(source));
	
	attachmentBodyPart.setFileName("a.gif");
 
	multipart.addBodyPart(attachmentBodyPart);
	}
	}
}
 
 
 
 
flex 4 code
 
 
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" xmlns:mk="services.mk.*" xmlns:fgg="services.fgg.*" xmlns:gett="services.gett.*">
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
 
			protected function button_clickHandler(event:MouseEvent):void
			{
				sendMailResult.token = gett.sendMail(arg0TextInput.text,arg1TextInput.text,arg2TextInput.text,arg3TextInput.text,new ArrayCollection());
			}
 
		]]>
	</fx:Script>
	<fx:Declarations>
		<gett:Gett id="gett" destination="mailaa" endpoint="http://localhost:8400/Project/messagebroker/amf" fault="Alert.show(event.fault.faultString)" showBusyCursor="true" source="Main"/>
		<s:CallResponder id="sendMailResult"/>
	</fx:Declarations>
	<mx:Form defaultButton="{button}">
		<mx:FormItem label="Arg0">
			<s:TextInput id="arg0TextInput"/>
		</mx:FormItem>
		<mx:FormItem label="Arg1">
			<s:TextInput id="arg1TextInput"/>
		</mx:FormItem>
		<mx:FormItem label="Arg2">
			<s:TextInput id="arg2TextInput"/>
		</mx:FormItem>
		<mx:FormItem label="Arg3">
			<s:TextInput id="arg3TextInput"/>
		</mx:FormItem>
		<s:Button label="SendMail" id="button" click="button_clickHandler(event)"/>
	</mx:Form>
	
</s:Application>
[+][-]10/01/09 11:51 PM, ID: 25475594Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Adobe Flex, Java Programming Language
Tags: send email java + flex 4
Sign Up Now!
Solution Provided By: objects
Participating Experts: 1
Solution Grade: A
 
[+][-]09/30/09 02:35 AM, ID: 25456848Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/30/09 02:36 AM, ID: 25456856Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/30/09 10:19 AM, ID: 25461066Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/30/09 10:21 AM, ID: 25461082Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/30/09 03:34 PM, ID: 25464314Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/01/09 09:33 AM, ID: 25470435Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/01/09 03:18 PM, ID: 25473714Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/01/09 09:33 PM, ID: 25475212Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/01/09 09:47 PM, ID: 25475260Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/01/09 11:43 PM, ID: 25475572Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625