You are not logged in.

  • Login

1

Friday, January 26th 2007, 9:09pm

E-Mail versenden mit Java

Hallo zusammen,

Ich habe mal eine Frage, ist es möglich mit Java eine E-Mail zuversenden?

Ich habe in der API geguckt, nur leider nichts mit E-Mail,email oder Mail gefunden, wenn ich Blind bin, dann Bitte drauf aufmerksam machen, danke :lol:

Schonmal vielen Dank,

Aleex

2

Friday, January 26th 2007, 11:40pm

Bist Blind *fg*

Habe dir mal was aus nem openbook rausgesucht:
http://www.galileocomputing.de/openbook/…insel16_010.htm

Denke mal das sollte helfen :-)

Gute Nacht^^

3

Friday, January 26th 2007, 11:43pm

Ich danke dir :D

Schlaf Gut ;)

4

Saturday, January 27th 2007, 12:06am

Hallo nochmal,

Auf der Seite werden Folgene Packete Importiert:

import javax.mail.*;
import javax.mail.internet.*;

Der Compiler sagt das es diese nicht gibt...

Kann das sein es die Funktionen nicht mehr gibt?

5

Saturday, January 27th 2007, 11:52am

Achso sorry.
Du musst noch die Java Mail Api und das Java Beans Activation Framework (JAF) in den Classpath packen
Kannst hier runterladen:

Mail Api
JAF


Wenn du beides im Classpath hast sollten auch die Imports wieder funktionieren.

Lg.
F0kus

6

Saturday, January 27th 2007, 1:33pm

Hallo,

Ich Danke dir, nur ein Problem hab ich, ich bin noch nicht so Lange in der Java programmierung, und deshalb weiß ich nicht was mit dem Classpath gemeint ist, für kurze Erklärung wäre ich dankbar.

EDIT//: Den Classpath hab ich, hab den Zip ordner entpackt, nur wo soll ich die beiden datein einfügen?

Aleex

7

Saturday, January 27th 2007, 2:26pm

Das ist letztendlich egal.... Wo du willst...

Ich hab auch mal probiert mit Java E-Mails zu verschicken. Mit GMail ist das die reinste Tortur. Habs dann aufgegeben ;)

8

Saturday, January 27th 2007, 2:27pm

Lach, ich lasse es auch :lol:

9

Saturday, January 27th 2007, 10:56pm

welchen Compiler benutzt du denn?
Bei den meisten heißt es "Biblitheken hinzufügen" oder sowas in der art.

10

Sunday, January 28th 2007, 2:06am

Ich benutze-> jdk 1.5.0_09...

Und davon den Compiler...

lg,

Aleex

11

Sunday, January 28th 2007, 9:54am

Er meinte vermutlich die IDE. Machst du alles in der Konsole?
Bei Eclipse heißt es auch "Add Library"

12

Sunday, January 28th 2007, 10:33am

Quoted from ""d0nUt""

Er meinte vermutlich die IDE. Machst du alles in der Konsole?
Bei Eclipse heißt es auch "Add Library"


ups, sorry genau das meint ich ;-)

13

Sunday, January 28th 2007, 2:46pm

Quoted from ""d0nUt""

Er meinte vermutlich die IDE. Machst du alles in der Konsole?
Bei Eclipse heißt es auch "Add Library"


Ja, mach ich...

14

Sunday, January 28th 2007, 3:22pm

puh, keine Ahnung.. ich nehme du musst die Classpath Variable erweitern.

15

Monday, January 29th 2007, 10:28am

Du meinst, du willst die beiden Mail JARs in deine JAR-Datei packen?
Das ist nicht notwendig!
Wenn du auf der Console compilierst musst du beim compilieren den CLASSPATH um den absoluten Pfad zu den JAR-Dateien ergänzen, und beim Ausführen sollten einfach alle JAR files im selben Verzeichnis liegen.

16

Monday, January 29th 2007, 3:10pm

Quoted from ""phax""

Du meinst, du willst die beiden Mail JARs in deine JAR-Datei packen?
Das ist nicht notwendig!
Wenn du auf der Console compilierst musst du beim compilieren den CLASSPATH um den absoluten Pfad zu den JAR-Dateien ergänzen, und beim Ausführen sollten einfach alle JAR files im selben Verzeichnis liegen.


Danke, ich werde es ausprobieren :D

17

Saturday, March 3rd 2007, 9:55pm

So... wollt kein neuen Thread dafür aufmachen, da meine Frage relativ viel mit dem bisherigen zu tun hat.

Also... die E-mail an sich verschicken klappt (glaub ich -> untested) aber wie bekomme ich einen dateianhang da rein?? habe leider nix weiter dazu gefunden...

Danke im vorraus :-)

lg.

18

Monday, March 5th 2007, 3:06pm

Mal ne Frage.
Was benutzt du zum Mail Versenden?
Solltest du javamail verwenden behaupte ich mal, dass du zu faul bist zu lesen =)
Nimms mir bitte nicht übel, bin "größtenteils harmlos"

Das hier ist ein Demoprogramm, was beim javamail dabei ist.
Hoffe es hilft

Java Quellcode

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
123
124
125
126
/*
 * @(#)sendfile.java	1.11 03/06/19
 *
 * Copyright 1996-2003 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 
 * - Redistribution in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * 
 * Neither the name of Sun Microsystems, Inc. or the names of contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
 * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR LIABILITIES
 * SUFFERED BY LICENSEE AS A RESULT OF  OR RELATING TO USE, MODIFICATION
 * OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
 * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
 * ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * 
 * You acknowledge that Software is not designed, licensed or intended
 * for use in the design, construction, operation or maintenance of any
 * nuclear facility.
 */
 
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
 
/**
 * sendfile will create a multipart message with the second
 * block of the message being the given file.<p>
 *
 * This demonstrates how to use the FileDataSource to send
 * a file via mail.<p>
 *
 * usage: <code>java sendfile <i>to from smtp file true|false</i></code>
 * where <i>to</i> and <i>from</i> are the destination and
 * origin email addresses, respectively, and <i>smtp</i>
 * is the hostname of the machine that has smtp server
 * running.  <i>file</i> is the file to send. The next parameter
 * either turns on or turns off debugging during sending.
 *
 * @author	Christopher Cotton
 */
public class sendfile {
 
    public static void main(String[] args) {
	if (args.length != 5) {
	    System.out.println("usage: java sendfile <to> <from> <smtp> <file> true|false");
	    System.exit(1);
	}
 
	String to = args[0];
	String from = args[1];
	String host = args[2];
	String filename = args[3];
	boolean debug = Boolean.valueOf(args[4]).booleanValue();
	String msgText1 = "Sending a file.\n";
	String subject = "Sending a file";
 
	// create some properties and get the default Session
	Properties props = System.getProperties();
	props.put("mail.smtp.host", host);
 
	Session session = Session.getInstance(props, null);
	session.setDebug(debug);
 
	try {
	    // create a message
	    MimeMessage msg = new MimeMessage(session);
	    msg.setFrom(new InternetAddress(from));
	    InternetAddress[] address = {new InternetAddress(to)};
	    msg.setRecipients(Message.RecipientType.TO, address);
	    msg.setSubject(subject);
 
	    // create and fill the first message part
	    MimeBodyPart mbp1 = new MimeBodyPart();
	    mbp1.setText(msgText1);
 
	    // create the second message part
	    MimeBodyPart mbp2 = new MimeBodyPart();
 
            // attach the file to the message
   	    FileDataSource fds = new FileDataSource(filename);
	    mbp2.setDataHandler(new DataHandler(fds));
	    mbp2.setFileName(fds.getName());
 
	    // create the Multipart and add its parts to it
	    Multipart mp = new MimeMultipart();
	    mp.addBodyPart(mbp1);
	    mp.addBodyPart(mbp2);
 
	    // add the Multipart to the message
	    msg.setContent(mp);
 
	    // set the Date: header
	    msg.setSentDate(new Date());
 
	    // send the message
	    Transport.send(msg);
 
	} catch (MessagingException mex) {
	    mex.printStackTrace();
	    Exception ex = null;
	    if ((ex = mex.getNextException()) != null) {
		ex.printStackTrace();
	    }
	}
    }
}


edit:
Was u.U. einigen helfen könnte, die Mails mit javamail versenden wollen. Bitte nicht vergessen activation.jar (JAVABEANS(tm) ACTIVATION FRAMEWORK, jaf) mit in den Classpath einzubinden. Sonst gibts ne nichtssagende Fehlermeldung.

19

Monday, March 5th 2007, 4:04pm

*lalalalalala*
*hust*
ja was soll ich sagen... danke? :-)

Hm ja.. Danke =) und sorry... war wieder sone "zwischen tür und angel" aktion^^

Lg. F0kus

20

Monday, March 5th 2007, 4:53pm

Hehe hoffe ich konnte dir helfen :)

Similar threads

Social bookmarks