Complete working code for Gmail POP3 & SMTP with SSL - Java mail API
Finally, your code-hunt has come to an end!!!!
I am presenting you the complete solution (with code) to send and retrieve you mails to & from GMAIL using SMTP and POP3 with SSL & Authenticaion enabled. [Even starters & newbies like me, can easy try, test & understand - But first download & add JAR's of Java Mail API & Java Activation Framework to Netbeans Library Manager]
Download Java Mail API here
http://java.sun.com/products/javamail/
Read Java Mail FAQ's here
http://java.sun.com/products/javamail/FAQ.html
Download Java Activation Framework [JAF]
http://java.sun.com/products/javabeans/jaf/downloads/index.html
Also, The POP program retrieves the mail sent with SMTP program :) [MOST IMPORTANT & LARGELY IN DEMAND]okey.. first things first... all of your thanks goes to the following and not a s@!te to me :)
hail Java !!
hail Java mail API !!
hail Java forums !!
hail Java-tips.org !!
hail Netbeans !!
Thanks to all coders who helped me by getting the code to work in one piece.
special thanks to "bshannon" - The dude who runs this forum from 97!!I am just as happy as you will be when you execute the below code!! [my 13 hours of tweaking & code hunting has paid off!!]
Now here it is...I only present you the complete solution!!
START OF PROGRAM 1
SENDING A MAIL FROM GMAIL ACCOUNT USING SMTP [STARTTLS (SSL)] PROTOCOL OF JAVA MAIL APINote on Program 1:
1. In the code below replace USERNAME & PASSWORD with your respective GMAIL account username and its corresponding password!
2. Use the code to make your Gmail client [jsp/servlets whatever]
//Mail.java - smtp sending starttls (ssl) authentication enabled
//1.Open a new Java class in netbeans (default package of the project) and name it as "Mail.java"
//2.Copy paste the entire code below and save it.
//3.Right click on the file name in the left side panel and click "compile" then click "Run"
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class Main
String d_email = "[email protected]",
d_password = "PASSWORD",
d_host = "smtp.gmail.com",
d_port = "465",
m_to = "[email protected]",
m_subject = "Testing",
m_text = "Hey, this is the testing email.";
public Main()
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", d_host);
props.put("mail.smtp.port", d_port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
try
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
//session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText(m_text);
msg.setSubject(m_subject);
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
Transport.send(msg);
catch (Exception mex)
mex.printStackTrace();
public static void main(String[] args)
Main blah = new Main();
private class SMTPAuthenticator extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
return new PasswordAuthentication(d_email, d_password);
END OF PROGRAM 1-----
START OF PROGRAM 2
RETRIVE ALL THE MAILS FROM GMAIL INBOX USING Post Office Protocol POP3 [SSL] PROTOCOL OF JAVA MAIL APINote:
1.Log into your gmail account via webmail [http://mail.google.com/]
2.Click on "settings" and select "Mail Forwarding & POP3/IMAP"
3.Select "enable POP for all mail" and "save changes"
4.In the code below replace USERNAME & PASSWORD with your respective GMAIL account username and its corresponding password!
PROGRAM 2 - PART 1 - Main.java
//1.Open a new Java class file in the default package
//2.Copy paste the below code and rename it to Mail.java
//3.Compile and execute this code.
public class Main {
/** Creates a new instance of Main */
public Main() {
* @param args the command line arguments
public static void main(String[] args) {
try {
GmailUtilities gmail = new GmailUtilities();
gmail.setUserPass("[email protected]", "PASSWORD");
gmail.connect();
gmail.openFolder("INBOX");
int totalMessages = gmail.getMessageCount();
int newMessages = gmail.getNewMessageCount();
System.out.println("Total messages = " + totalMessages);
System.out.println("New messages = " + newMessages);
System.out.println("-------------------------------");
//Uncomment the below line to print the body of the message. Remember it will eat-up your bandwidth if you have 100's of messages. //gmail.printAllMessageEnvelopes();
gmail.printAllMessages();
} catch(Exception e) {
e.printStackTrace();
System.exit(-1);
END OF PART 1
PROGRAM 2 - PART 2 - GmailUtilities.java
//1.Open a new Java class in the project (default package)
//2.Copy paste the below code
//3.Compile - Don't execute this[Run]
import com.sun.mail.pop3.POP3SSLStore;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.FetchProfile;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.URLName;
import javax.mail.internet.ContentType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.ParseException;
public class GmailUtilities {
private Session session = null;
private Store store = null;
private String username, password;
private Folder folder;
public GmailUtilities() {
public void setUserPass(String username, String password) {
this.username = username;
this.password = password;
public void connect() throws Exception {
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
Properties pop3Props = new Properties();
pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
pop3Props.setProperty("mail.pop3.port", "995");
pop3Props.setProperty("mail.pop3.socketFactory.port", "995");
URLName url = new URLName("pop3", "pop.gmail.com", 995, "",
username, password);
session = Session.getInstance(pop3Props, null);
store = new POP3SSLStore(session, url);
store.connect();
public void openFolder(String folderName) throws Exception {
// Open the Folder
folder = store.getDefaultFolder();
folder = folder.getFolder(folderName);
if (folder == null) {
throw new Exception("Invalid folder");
// try to open read/write and if that fails try read-only
try {
folder.open(Folder.READ_WRITE);
} catch (MessagingException ex) {
folder.open(Folder.READ_ONLY);
public void closeFolder() throws Exception {
folder.close(false);
public int getMessageCount() throws Exception {
return folder.getMessageCount();
public int getNewMessageCount() throws Exception {
return folder.getNewMessageCount();
public void disconnect() throws Exception {
store.close();
public void printMessage(int messageNo) throws Exception {
System.out.println("Getting message number: " + messageNo);
Message m = null;
try {
m = folder.getMessage(messageNo);
dumpPart(m);
} catch (IndexOutOfBoundsException iex) {
System.out.println("Message number out of range");
public void printAllMessageEnvelopes() throws Exception {
// Attributes & Flags for all messages ..
Message[] msgs = folder.getMessages();
// Use a suitable FetchProfile
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
folder.fetch(msgs, fp);
for (int i = 0; i < msgs.length; i++) {
System.out.println("--------------------------");
System.out.println("MESSAGE #" + (i + 1) + ":");
dumpEnvelope(msgs);
public void printAllMessages() throws Exception {
// Attributes & Flags for all messages ..
Message[] msgs = folder.getMessages();
// Use a suitable FetchProfile
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
folder.fetch(msgs, fp);
for (int i = 0; i < msgs.length; i++) {
System.out.println("--------------------------");
System.out.println("MESSAGE #" + (i + 1) + ":");
dumpPart(msgs[i]);
public static void dumpPart(Part p) throws Exception {
if (p instanceof Message)
dumpEnvelope((Message)p);
String ct = p.getContentType();
try {
pr("CONTENT-TYPE: " + (new ContentType(ct)).toString());
} catch (ParseException pex) {
pr("BAD CONTENT-TYPE: " + ct);
* Using isMimeType to determine the content type avoids
* fetching the actual content data until we need it.
if (p.isMimeType("text/plain")) {
pr("This is plain text");
pr("---------------------------");
System.out.println((String)p.getContent());
} else {
// just a separator
pr("---------------------------");
public static void dumpEnvelope(Message m) throws Exception {
pr(" ");
Address[] a;
// FROM
if ((a = m.getFrom()) != null) {
for (int j = 0; j < a.length; j++)
pr("FROM: " + a[j].toString());
// TO
if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
for (int j = 0; j < a.length; j++) {
pr("TO: " + a[j].toString());
// SUBJECT
pr("SUBJECT: " + m.getSubject());
// DATE
Date d = m.getSentDate();
pr("SendDate: " +
(d != null ? d.toString() : "UNKNOWN"));
static String indentStr = " ";
static int level = 0;
* Print a, possibly indented, string.
public static void pr(String s) {
System.out.print(indentStr.substring(0, level * 2));
System.out.println(s);
}END OF PART 2
END OF PROGRAM 2
P.S: CHECKING !!
STEP 1.
First compile and execute the PROGRAM 1 with your USERNAME & PASSWORD. This will send a mail to your own account.
STEP 2.
Now compile both PART 1 & PART 2 of PROGRAM 2. Then, execute PART 1 - Main.java. This will retrive the mail sent in step 1. njoy! :)
In future, I hope this is added to the demo programs of the Java Mail API download package.
This is for 3 main reasons...
1. To prevent a lot of silly questions being posted on this forum [like the ones I did :(].
2. To give the first time Java Mail user with a real time working example without code modification [code has to use command line args like the demo programs - for instant results].
3. Also, this is what google has to say..
"The Gmail Team is committed to making sure you always can access your mail. That's why we're offering POP access and auto-forwarding. Both features are free for all Gmail users and we have no plans to charge for them in the future."
http://mail.google.com/support/bin/answer.py?answer=13295
I guess bshannon & Java Mail team is hearing this....
Again, Hurray and thanks for helping me make it!! cheers & no more frowned faces!!
(: (: (: (: (: GO JCODERS GO!! :) :) :) :) :)
codeace
-----
Thanks for the reply,
I did checked by enabling session debuging and also checked pop settings it's enabled for all
mails, I tried deleting some very old messages and now the message count is changed to 310.
This may be the problem with gmail.
Bellow is the output i got,
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
DEBUG POP3: connecting to host "pop.gmail.com", port 995, isSSL false
S: +OK Gpop ready for requests from 121.243.255.240 n22pf5432603pof.2
C: USER [email protected]
S: +OK send PASS
C: PASS my_password
S: +OK Welcome.
C: STAT
S: +OK 310 26900234
Custom output: messageCount : 310
C: QUIT
S: +OK Farewell.
Similar Messages
-
How can i access gmail's smtp server using java mail api
i m using java mail api to access gmails pop and smtp service to receive and send mail from ur gmail account. I m able to access gmails pop server using the ssl and port 995 , but i can not use its smtp server to which i m connecting using ssl on 465 port. It requires authentication code.
if anybody can help me in this regard i m thnkful to him/her.
thnks in advance.
jogin desaiHere's an example of using SSL + Authentication
http://onesearch.sun.com/search/onesearch/index.jsp?qt=ssl+authentication&subCat=siteforumid%3Ajava43&site=dev&dftab=siteforumid%3Ajava43&chooseCat=javaall&col=developer-forums -
How to create a transaction code for a function group with screen 100 as st
Hello ,
I have requirement where I need to create a function group and create screen 100, 200, 300 and include the function in the screens.
Customer asked me to create a transaction with the screen 100 as the starting screen.
Can you please let me know how to create a transaction code for a function group with screen 100 as starting screen.
[ It is not a module pool program ].
Thanks
Prashanth.
Moderator message - Please ask a specific question and do not ask the forum to do your work for you - post locked
Edited by: Rob Burbank on Jun 2, 2009 11:49 AMGo to transaction SE93, enter a transaction code that you want and click on "create". Enter a text and select the "Transaction with Parameters" button. In the Default Values section, enter START_REPORT in the transaction field. Check the "skip initial screen" box. In the Name of Screen field section enter the following lines:
Name of screen field: Value
D_SREPOVARI-REPORTTYPE RW
D_SREPOVARI-REPORT ZPCA
Save and transport accordingly. -
Needed example working code for FM"LAST_DAY_IN_PERIOD_GET"
needed example working code for FM"LAST_DAY_IN_PERIOD_GET"
Hi,
Go through this code
*& Report Z_FICO_REP_SHIPMENTS
REPORT z_fico_rep_shipments MESSAGE-ID sd.
TYPE-POOLS : slis.
TABLES : vbak,
kna1,
likp,
vbfa.
*>> DEFINE global Types
TYPES : BEGIN OF gt_vbak,
vbeln TYPE vbeln,
kunnr TYPE kunnr ,
spart TYPE spart,
audat TYPE audat,
END OF gt_vbak,
BEGIN OF gt_kna1,
kunnr TYPE kunnr,
name1 TYPE name1,
END OF gt_kna1,
BEGIN OF gt_likp,
vbeln TYPE vbeln,
wadat_ist TYPE wadat_ist,
END OF gt_likp,
BEGIN OF gt_vbfa,
vbelv TYPE vbelv,
erdat TYPE erdat,
rfwrt TYPE rfwrt,
END OF gt_vbfa,
BEGIN OF gt_final,
kunnr TYPE kunnr,
name1 TYPE name1,
cumon TYPE monat,
trcum TYPE rfwrt,
trcuy TYPE rfwrt,
perce TYPE rfwrt,
fiscy TYPE gjahr,
ftrcum TYPE rfwrt,
ftrcuy TYPE rfwrt,
fperce TYPE rfwrt,
END OF gt_final.
DATA : gwa_vbak TYPE gt_vbak,
gwa_kna1 TYPE gt_kna1,
gwa_likp TYPE gt_likp,
gwa_vbfa TYPE gt_vbfa,
gwa_final TYPE gt_final,
gwa_sort TYPE slis_sortinfo_alv,
gwa_layout TYPE slis_layout_alv. "ALV Layout
DATA : gi_vbak TYPE STANDARD TABLE OF gt_vbak,
gi_kna1 TYPE STANDARD TABLE OF gt_kna1,
gi_likp TYPE STANDARD TABLE OF gt_likp,
gi_vbfa TYPE STANDARD TABLE OF gt_vbfa,
gi_likp1 TYPE STANDARD TABLE OF gt_likp,
gi_vbfa1 TYPE STANDARD TABLE OF gt_vbfa,
gi_final TYPE STANDARD TABLE OF gt_final WITH HEADER LINE,
gi_final1 TYPE STANDARD TABLE OF gt_final WITH HEADER LINE.
*>> DEFINE INTERNAL TABLE
DATA : gi_fieldcat TYPE slis_t_fieldcat_alv, "ALV Fieldcatalog
gi_events TYPE slis_t_event, "ALV EventS
gi_sort TYPE slis_t_sortinfo_alv ,
gi_top_of_page TYPE slis_t_listheader. "ALV LIST HEADER
DATA : gv_month(2) TYPE n.
*>> GLOBAL CONSTANTS
CONSTANTS: gc_day(2) TYPE n VALUE 01,
gc_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',
gc_x TYPE c VALUE 'X'.
SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_monat TYPE monat OBLIGATORY,
p_gjahr TYPE gjahr OBLIGATORY.
SELECT-OPTIONS : s_bukrs FOR vbak-bukrs_vf OBLIGATORY,
s_vkorg FOR vbak-vkorg,
s_spart FOR vbak-spart OBLIGATORY,
s_audat FOR vbak-audat NO-DISPLAY.
SELECTION-SCREEN:END OF BLOCK b1.
SELECTION-SCREEN:BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.
PARAMETERS: p_det RADIOBUTTON GROUP grp DEFAULT 'X' ,
p_sum RADIOBUTTON GROUP grp.
SELECTION-SCREEN:END OF BLOCK b2.
START-OF-SELECTION.
*>> Take Period And year and find starting and ending date
PERFORM fiscal_date.
PERFORM collect_data.
PERFORM manipulation_collect_data.
END-OF-SELECTION.
*>> Sort
PERFORM gi_sort_table.
*>> MEARGE FIELD CATALOG USING INTERNAL TABLE
PERFORM mearge_field_catalog.
*>> SET EVENTS
PERFORM set_event.
*>> FOR ALV HEADER
PERFORM n_top_of_page USING gi_top_of_page[].
*>>For ALV Layout
PERFORM build_layout.
*>>For output display
PERFORM alv_grid_display.
*& Form fiscal_date
FORM fiscal_date.
TYPES : BEGIN OF lt_fisc,
bukrs TYPE bukrs,
periv TYPE periv,
bumon TYPE bumon,
butag TYPE butag,
END OF lt_fisc,
BEGIN OF lt_t009b,
periv TYPE periv,
bumon TYPE bumon,
butag TYPE butag,
poper TYPE poper,
END OF lt_t009b.
DATA : lwa_fisc TYPE lt_fisc,
lwa_t009b TYPE lt_t009b.
DATA : li_fisc TYPE STANDARD TABLE OF lt_fisc,
li_t009b TYPE STANDARD TABLE OF lt_t009b.
DATA : lv_date(2) TYPE c,
lv_mont(2) TYPE c,
lv_year(4) TYPE c.
SELECT bukrs periv FROM t001
INTO TABLE li_fisc
WHERE bukrs IN s_bukrs.
IF sy-subrc EQ 0.
SELECT * FROM t009b
INTO CORRESPONDING FIELDS OF TABLE li_t009b
FOR ALL ENTRIES IN li_fisc
WHERE periv EQ li_fisc-periv .
IF sy-subrc NE 0.
CLEAR li_t009b.
ENDIF.
ELSE.
CLEAR li_fisc.
ENDIF.
SORT li_t009b BY periv poper.
LOOP AT li_fisc INTO lwa_fisc.
READ TABLE li_t009b INTO lwa_t009b WITH KEY periv = lwa_fisc-periv
poper = '001'
BINARY SEARCH.
IF sy-subrc = 0.
s_audat-option = 'EQ'.
s_audat-sign = 'I'.
CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = p_gjahr
i_periv = lwa_t009b-periv
i_poper = lwa_t009b-poper
IMPORTING
e_date = s_audat-low.
ENDIF.
CLEAR lwa_t009b.
READ TABLE li_t009b INTO lwa_t009b WITH KEY periv = lwa_fisc-periv
poper = '012'
BINARY SEARCH.
IF sy-subrc = 0.
CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = p_gjahr
i_periv = lwa_t009b-periv
i_poper = lwa_t009b-poper
IMPORTING
e_date = s_audat-high.
ENDIF.
CLEAR lwa_t009b.
READ TABLE li_t009b INTO lwa_t009b WITH KEY periv = lwa_fisc-periv
poper = p_monat
BINARY SEARCH.
IF sy-subrc = 0.
lv_date = s_audat-high+6(2).
lv_mont = s_audat-high+4(2).
lv_year = s_audat-high(4).
lv_mont = lwa_t009b-bumon.
lv_date = lwa_t009b-butag.
CONCATENATE lv_year lv_mont lv_date INTO s_audat-high.
APPEND s_audat.
CLEAR: lwa_fisc,lwa_t009b,lv_date,lv_mont,lv_year.
ENDIF.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM s_audat.
ENDFORM. "fiscal_date
*& Form collect_data
FORM collect_data .
SELECT vbeln kunnr spart audat
FROM vbak
INTO TABLE gi_vbak
WHERE audat GE s_audat-low AND
audat LT s_audat-high AND
vkorg IN s_vkorg AND
spart IN s_spart AND
bukrs_vf IN s_bukrs.
IF sy-subrc EQ 0.
SELECT kunnr name1
FROM kna1
INTO TABLE gi_kna1
FOR ALL ENTRIES IN gi_vbak
WHERE kunnr EQ gi_vbak-kunnr.
IF sy-subrc NE 0.
CLEAR gi_kna1.
ENDIF.
SELECT vbeln wadat_ist
FROM likp
INTO TABLE gi_likp
WHERE wadat_ist GE s_audat-low AND
wadat_ist LT s_audat-high .
IF sy-subrc EQ 0.
SELECT vbelv erdat rfwrt
FROM vbfa
INTO TABLE gi_vbfa
FOR ALL ENTRIES IN gi_likp
WHERE vbeln = gi_likp-vbeln AND
( vbtyp_n = 'M' OR
vbtyp_n = 'H' ) .
IF sy-subrc NE 0.
CLEAR gi_vbfa.
ENDIF.
ELSE.
CLEAR gi_likp.
ENDIF.
PERFORM change_date.
SELECT vbeln wadat_ist
FROM likp
INTO TABLE gi_likp1
WHERE wadat_ist GE s_audat-low AND
wadat_ist LT s_audat-high .
IF sy-subrc EQ 0.
SELECT vbelv erdat rfwrt
FROM vbfa
INTO TABLE gi_vbfa1
FOR ALL ENTRIES IN gi_likp1
WHERE vbeln = gi_likp1-vbeln AND
( vbtyp_n = 'M' OR
vbtyp_n = 'H' ) .
IF sy-subrc NE 0.
CLEAR gi_vbfa.
ENDIF.
ELSE.
CLEAR gi_likp.
ENDIF.
ELSE.
MESSAGE i261.
LEAVE SCREEN.
ENDIF.
ENDFORM. "collect_data
*& Form Manipulation_collect_data
FORM manipulation_collect_data.
SORT gi_vbak BY vbeln.
SORT gi_kna1 BY kunnr.
LOOP AT gi_vbak INTO gwa_vbak.
MOVE-CORRESPONDING gwa_vbak TO gwa_final.
READ TABLE gi_kna1 INTO gwa_kna1 WITH KEY kunnr = gwa_vbak-kunnr
BINARY SEARCH.
IF sy-subrc EQ 0.
gwa_final-name1 = gwa_kna1-name1.
ENDIF.
ENDLOOP.
* v_month = gwa_vbak-audat+4(2).
* gwa_final-cumon = p_monat.
* gwa_final-fiscy = p_gjahr.
* IF v_month = p_monat.
* CLEAR wa_ckmlhd.
* READ TABLE i_ckmlhd INTO wa_ckmlhd WITH KEY matnr = wa_vbap-matnr
* bwkey = wa_vbap-werks
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* CLEAR i_nckmlcr.
* READ TABLE i_nckmlcr INTO wa_nckmlcr
* WITH KEY kalnr = wa_ckmlhd-kalnr
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* gwa_final-peinh = wa_nckmlcr-peinh.
* gwa_final-kzwi6 = wa_vbap-kzwi6 - wa_vbap-kzwi5.
* gwa_final-kzwi5 = wa_vbap-kzwi5.
* gwa_final-totre = gwa_final-kzwi6 + gwa_final-kzwi5.
* gwa_final-actco = ( wa_nckmlcr-pvprs / wa_nckmlcr-peinh ) *
* wa_vbap-kwmeng.
* gwa_final-profit = gwa_final-totre - gwa_final-actco.
* gwa_final-prows = ( gwa_final-profit - gwa_final-kzwi6 ) *
*100.
* ENDIF.
* ENDIF.
* ELSE.
* CLEAR wa_ckmlhd.
* READ TABLE i_ckmlhd INTO wa_ckmlhd WITH KEY matnr = wa_vbap-matnr
* bwkey = wa_vbap-werks
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* READ TABLE i_ckmlcr INTO wa_ckmlcr
* WITH KEY kalnr = wa_ckmlhd-kalnr
* BINARY SEARCH.
* IF sy-subrc NE 0.
* CLEAR wa_ckmlcr.
* ENDIF.
* CLEAR wa_nckmlcr.
* READ TABLE i_nckmlcr INTO wa_nckmlcr
* WITH KEY kalnr = wa_ckmlhd-kalnr
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* gwa_final-fkzwi6 = wa_vbap-kzwi6 - wa_vbap-kzwi5.
* gwa_final-fkzwi5 = wa_vbap-kzwi5.
* gwa_final-ftotre = gwa_final-fkzwi6 + gwa_final-fkzwi5.
* gwa_final-factco = ( ( wa_nckmlcr-pvprs / wa_ckmlcr-peinh )
* * wa_vbap-kwmeng ) / wa_nckmlcr-count.
* gwa_final-fprofit = gwa_final-ftotre - gwa_final-factco.
* gwa_final-fprows = ( gwa_final-fprofit - gwa_final-kzwi6 ) *
*100
* ENDIF.
* ENDIF.
* ENDIF.
* APPEND gwa_final TO gi_final.
* CLEAR : gwa_final,wa_nckmlcr,wa_ckmlcr,wa_ckmlhd,
* gwa_vbak,wa_vbap,gwa_kna1.
* ENDLOOP.
* gwa_final-matnr = space.gwa_final-vbeln = space.
* MODIFY gi_final FROM gwa_final TRANSPORTING vbeln matnr
* WHERE matnr NE space.
* SORT gi_final BY kunnr vbeln matnr.
* IF p_sum = gc_x.
* LOOP AT gi_final INTO gwa_final.
* COLLECT gwa_final INTO gi_final1.
* ENDLOOP.
* CLEAR gwa_final.REFRESH gi_final.
* gi_final[] = gi_final1[].
* ENDIF.
ENDFORM. "manipulation_collect_data
*& Form change_date
FORM change_date.
DATA : lv_date(2) TYPE c,
lv_mont(2) TYPE c,
lv_year(4) TYPE n.
lv_date = s_audat-low+6(2).
lv_mont = s_audat-low+4(2).
lv_year = s_audat-low(4).
lv_year = lv_year - 1.
CONCATENATE lv_year lv_mont lv_date INTO s_audat-low.
CLEAR : lv_date ,lv_mont,lv_year.
lv_date = s_audat-high+6(2).
lv_mont = s_audat-high+4(2).
lv_year = s_audat-high(4).
lv_year = lv_year - 1.
CONCATENATE lv_year lv_mont lv_date INTO s_audat-high.
CLEAR : lv_date ,lv_mont,lv_year.
ENDFORM. " change_date
*& Form gi_sort_table
FORM gi_sort_table.
IF p_det = gc_x.
gwa_sort-spos = '1'.
gwa_sort-fieldname = 'KUNNR'.
gwa_sort-tabname = 'gi_final'.
gwa_sort-up = gc_x.
gwa_sort-subtot = gc_x.
APPEND gwa_sort TO gi_sort.
CLEAR gwa_sort.
gwa_sort-spos = '2'.
gwa_sort-fieldname = 'NAME1'.
gwa_sort-tabname = 'gi_final'.
gwa_sort-up = gc_x.
APPEND gwa_sort TO gi_sort.
* ELSE.
* gwa_sort-spos = '1'.
* gwa_sort-fieldname = 'KUNNR'.
* gwa_sort-tabname = 'gi_final'.
* gwa_sort-up = gc_x.
* APPEND gwa_sort TO gi_sort.
* CLEAR gwa_sort.
* gwa_sort-spos = '2'.
* gwa_sort-fieldname = 'NAME1'.
* gwa_sort-tabname = 'gi_final'.
* gwa_sort-up = gc_x.
* gwa_sort-group = gc_x.
* gwa_sort-subtot = gc_x.
* APPEND gwa_sort TO gi_sort.
ENDIF.
ENDFORM. "gi_sort_table
*& Form mearge_field_catalog
FORM mearge_field_catalog .
*>> LOCAL WORK AREA FOR FIELDCATALOG
DATA : lwa_fieldcata TYPE slis_fieldcat_alv.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'KUNNR'.
* lwa_fieldcata-col_pos = 1.
lwa_fieldcata-key = 'X'.
lwa_fieldcata-key_sel = 'X'.
lwa_fieldcata-ref_tabname = 'KNA1'.
lwa_fieldcata-seltext_l = 'Customer No.'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'NAME1'.
* lwa_fieldcata-col_pos = 2.
lwa_fieldcata-ref_tabname = 'KNA1'.
lwa_fieldcata-seltext_l = 'Customer Name'.
APPEND lwa_fieldcata TO gi_fieldcat.
IF p_det = gc_x.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'VBELN'.
* lwa_fieldcata-col_pos = 3.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Sales Order Number'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'MATNR'.
* lwa_fieldcata-col_pos = 4.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Material No.'.
APPEND lwa_fieldcata TO gi_fieldcat.
ENDIF.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'KWMENG'.
lwa_fieldcata-col_pos = 5.
lwa_fieldcata-ref_tabname = 'VBAP'.
lwa_fieldcata-do_sum = 'X'.
lwa_fieldcata-seltext_l = 'Order Quantity'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'PEINH'.
lwa_fieldcata-col_pos = 6.
lwa_fieldcata-ref_tabname = 'CKMLCR'.
lwa_fieldcata-text_fieldname = 'PEINH'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'CUMON'.
lwa_fieldcata-col_pos = 7.
lwa_fieldcata-ref_tabname = 'VBKPF'.
lwa_fieldcata-seltext_l = 'Month'.
lwa_fieldcata-no_sum = gc_x.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'KZWI6'.
lwa_fieldcata-col_pos = 8.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Costed Sales'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'KZWI5'.
lwa_fieldcata-col_pos = 9.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Surcharges'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'TOTRE'.
lwa_fieldcata-col_pos = 10.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Total Revenues'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'ACTCO'.
lwa_fieldcata-col_pos = 11.
lwa_fieldcata-ref_tabname = 'VBAP'.
lwa_fieldcata-seltext_l = 'Actual Cost for Period'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'PROFIT'.
lwa_fieldcata-col_pos = 12.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Profit'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'PROWS'.
lwa_fieldcata-col_pos = 13.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Profit % w/surcharge'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'FISCY'.
lwa_fieldcata-col_pos = 14.
* lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Fiscal Year'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'FKZWI6'.
lwa_fieldcata-col_pos = 15.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Costed Sales'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'FKZWI5'.
lwa_fieldcata-col_pos = 16.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Surcharges'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'FTOTRE'.
lwa_fieldcata-col_pos = 17.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Total Revenues'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'FACTCO'.
lwa_fieldcata-col_pos = 18.
lwa_fieldcata-ref_tabname = 'VBAP'.
lwa_fieldcata-seltext_l = 'Actual Cost for Period'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'FPROFIT'.
lwa_fieldcata-col_pos = 19.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Profit'.
APPEND lwa_fieldcata TO gi_fieldcat.
CLEAR lwa_fieldcata.
lwa_fieldcata-fieldname = 'FPROWS'.
lwa_fieldcata-col_pos = 20.
lwa_fieldcata-ref_tabname = 'VBAK'.
lwa_fieldcata-seltext_l = 'Profit % w/surcharge'.
APPEND lwa_fieldcata TO gi_fieldcat.
ENDFORM. " mearge_field_catalog
*& Form set_event
FORM set_event .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 1
IMPORTING
et_events = gi_events.
SORT gi_events BY name.
*-- To read Top of Page event
PERFORM read_events USING slis_ev_top_of_page gc_top_of_page.
ENDFORM. " set_event
*& Form top_of_page
FORM n_top_of_page USING lp_top_of_page TYPE slis_t_listheader.
DATA: lwa_listhead TYPE slis_listheader,
lv_ccode TYPE string,
lv_sales TYPE string,
lv_divis TYPE string.
CONCATENATE 'From : ' s_bukrs-low ' To: ' s_bukrs-high INTO lv_ccode.
CONCATENATE 'From: ' s_vkorg-low ' To: ' s_vkorg-high INTO lv_sales.
CONCATENATE 'From: ' s_spart-low ' To: ' s_spart-high INTO lv_divis.
CLEAR lwa_listhead.
lwa_listhead-typ = 'H'.
lwa_listhead-info = text-003.
APPEND lwa_listhead TO lp_top_of_page.
CLEAR lwa_listhead.
lwa_listhead-typ = 'S'.
lwa_listhead-key = 'Month'.
lwa_listhead-info = p_monat.
APPEND lwa_listhead TO lp_top_of_page.
CLEAR lwa_listhead.
lwa_listhead-typ = 'S'.
lwa_listhead-key = 'Year'.
lwa_listhead-info = p_gjahr.
APPEND lwa_listhead TO lp_top_of_page.
CLEAR lwa_listhead.
lwa_listhead-typ = 'S'.
lwa_listhead-key = 'Company Code'.
lwa_listhead-info = lv_ccode.
APPEND lwa_listhead TO lp_top_of_page.
CLEAR lwa_listhead.
lwa_listhead-typ = 'S'.
lwa_listhead-key = 'Sales Org'.
lwa_listhead-info = lv_sales.
APPEND lwa_listhead TO lp_top_of_page.
CLEAR lwa_listhead.
lwa_listhead-typ = 'S'.
lwa_listhead-key = 'Division'.
lwa_listhead-info = lv_divis.
APPEND lwa_listhead TO lp_top_of_page.
IF p_det = gc_x.
CLEAR lwa_listhead.
lwa_listhead-typ = 'A'.
lwa_listhead-info = text-004.
APPEND lwa_listhead TO lp_top_of_page.
ELSE.
CLEAR lwa_listhead.
lwa_listhead-typ = 'A'.
lwa_listhead-info = text-005.
APPEND lwa_listhead TO lp_top_of_page.
ENDIF.
ENDFORM. "top_of_page
*& Form TOP_OF_PAGE
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = gi_top_of_page.
ENDFORM. "TOP_OF_PAGE
*& Form build_layout
FORM build_layout .
gwa_layout-no_input = gc_x.
gwa_layout-colwidth_optimize = gc_x.
gwa_layout-zebra = gc_x.
ENDFORM. "build_layout
*& Form alv_grid_display
FORM alv_grid_display .
* Function module to display ALV report
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = gwa_layout
it_fieldcat = gi_fieldcat[]
it_sort = gi_sort
i_save = 'A'
it_events = gi_events[]
TABLES
t_outtab = gi_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " alv_grid_display
*& Form read_events
FORM read_events USING pr_events TYPE slis_alv_event-name
pr_eventname TYPE slis_formname.
DATA: lwa_event TYPE slis_alv_event.
CLEAR lwa_event.
READ TABLE gi_events INTO lwa_event
WITH KEY name = pr_events BINARY SEARCH.
IF sy-subrc = 0.
MOVE pr_eventname TO lwa_event-form.
MODIFY gi_events FROM lwa_event
TRANSPORTING form
WHERE name = pr_events.
ENDIF.
ENDFORM. " read_events
Regards
Sandipan -
I Seek code for programming lego minstorm with labview
Hi,
I'am building a car with lego mindstorm for a project and i seek code for programming my car with labview. If you already use labview for programming lego mindstorm, can you send exemples codes for see how the car do for move or turn. please.
Thanksduplicate post
duplicate post
Please try to keep your question to one thread. Otherwise people don't know where to respond. -
Example code for each and every class in java API
hi,
Is there any place where i can get example code for eacha and every class in java API.
for eample...if i wanna find sample codes for all the clases in java.lang.*
please let me know ASAP.
thanks in advanceCrossposted here: http://forum.java.sun.com/thread.jsp?thread=570264&forum=54&message=2820774
-
Hi
We have a requirement to create a custom e mail. For the same I am trying to use Java Mail API.I am facing an issue with the following code:
session session1 = session.getInstance(properties, null);
System gives an error Sourced file: inline evaluation of: ``Properties props = new Properties(); session session1 = session.getInstance(prop . . . '' : Typed variable declaration : Class: session not found in namespace
Is there some specific API i need to import for session class. Kindly suggest.
Regards
ShobhaHi Shobha,
I was also facing the same issue from last couple of weeks and just now i have achieved the working functionality.
Please find below working code and replace values as per your serveru2019s configuration.
import com.sap.odp.api.util.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.File;
import java.net.*;
// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to =<email address>;
String from =<email address>;
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = <smtp host name>;
String user = <smtp user name>;
// Create properties, get Session
// Properties props = new Properties();
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", host);
props.put("mail.debug", "false");
props.put("mail.smtp.auth", "false");
props.put("mail.user",user);
props.put("mail.from",from);
Session d_session = Session.getInstance(props,null);//Authenticator object need to be set
Message msg = new MimeMessage(d_session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());
msg.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" +
"Here is line 2.");
Transport.send(msg);
Deepak!!! -
Problem using Java Mail API with WLS 7.0
Hi All,
I am trying to use the Java Mail API provided by WLS 7.0. I have made the
settings metioned in the WLS 7.0 docs. However when I try to run the program I
am getting the following error:
javax.naming.NoInitialContextException: Need to specify class name in environment
or system property, or as an applet parameter, or in an application resource file:
java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
46)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
a:283)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
The code that I have written is as follows
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
public class MailTo {
public static void main(String args[])
try
//Context ic = getInitialContext();
InitialContext ic = new InitialContext();
/* My jndi name is "testSession" */
Session session = (Session) ic.lookup("testSession"); /* THE PROBLEM IS SHOWN
IN THIS LINE */
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "XX.XX.XX.XX");
/* For security reasons I have written the ip add in this format */
props.put("mail.from", "[email protected]"); /* for security reasons i have
changed the mail address */
Session session2 = session.getInstance(props);
Message msg = new MimeMessage(session2);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]",
false));
msg.setSubject("Test Message");
msg.setSentDate(new Date());
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp);
msg.setContent(mp);
Transport.send(msg);
catch(Exception e)
e.printStackTrace();
}//end of main
public static Context getInitialContext()
throws NamingException
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7501/testWebApp");
p.put(Context.SECURITY_PRINCIPAL, "weblogic");
p.put(Context.SECURITY_CREDENTIALS, "weblogic");
return new InitialContext(p);
}//end of class
Can anyone please tell me what is the problem. I thought that we cannot directly
do
InitialContext ic = new InitialContext();
So I had written a method getInitialContext() as shown in the above piece of code,
but that too did not work.
Eagerly awaiting a response.
Jimmy ShahYou can use InitialContext ic = new InitialContext() only if you are using a startup class, servlet or a JSP i.e
server side code.
If you are using a java client you need to use Context ic = getInitialContext();
Try this code
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
public class MailTo {
public static void main(String args[])
try {
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ic = new InitialContext(h);
Session session = (Session) ic.lookup("testSession");
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "XX.XX.XX.XX");
props.put("mail.from", "[email protected]");
Session session2 = session.getInstance(props);
Message msg = new MimeMessage(session2);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("[email protected]",false));
msg.setSubject("Test Message");
msg.setSentDate(new Date());
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp);
msg.setContent(mp);
Transport.send(msg);
catch(Exception e)
e.printStackTrace();
}//end of main
}//end of class
We have shipped a javamail example in the samples\server\src\examples\javamail folder.
Jimmy Shah wrote:
Hi All,
I am trying to use the Java Mail API provided by WLS 7.0. I have made the
settings metioned in the WLS 7.0 docs. However when I try to run the program I
am getting the following error:
javax.naming.NoInitialContextException: Need to specify class name in environment
or system property, or as an applet parameter, or in an application resource file:
java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
46)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
a:283)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
The code that I have written is as follows
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
public class MailTo {
public static void main(String args[])
try
//Context ic = getInitialContext();
InitialContext ic = new InitialContext();
/* My jndi name is "testSession" */
Session session = (Session) ic.lookup("testSession"); /* THE PROBLEM IS SHOWN
IN THIS LINE */
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "XX.XX.XX.XX");
/* For security reasons I have written the ip add in this format */
props.put("mail.from", "[email protected]"); /* for security reasons i have
changed the mail address */
Session session2 = session.getInstance(props);
Message msg = new MimeMessage(session2);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]",
false));
msg.setSubject("Test Message");
msg.setSentDate(new Date());
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp);
msg.setContent(mp);
Transport.send(msg);
catch(Exception e)
e.printStackTrace();
}//end of main
public static Context getInitialContext()
throws NamingException
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7501/testWebApp");
p.put(Context.SECURITY_PRINCIPAL, "weblogic");
p.put(Context.SECURITY_CREDENTIALS, "weblogic");
return new InitialContext(p);
}//end of class
Can anyone please tell me what is the problem. I thought that we cannot directly
do
InitialContext ic = new InitialContext();
So I had written a method getInitialContext() as shown in the above piece of code,
but that too did not work.
Eagerly awaiting a response.
Jimmy Shah--
Rajesh Mirchandani
Developer Relations Engineer
BEA Support -
Java mail api - sending mails to gmail account
Hello
I am using java mail api to send mails.when i send mails to gmail from ids which are not in gmail friends list, most of the mails are going to spam.Ofcourse, some of them go to inbox.I tried in lot of ways to analyse the problem.But nothing could help. Can anyone plzz tell me how to avoid mails going to spam in gmail, using java mail api?
Thank you in advance,
Regards,
Aradhana
Message was edited by:
Aradhanaam using the below code.
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port","25");
props.put("mail.smtp.auth", isAuth);
Authenticator auth = new UserAuthenticator();
// Get session
Session s = Session.getDefaultInstance(props,auth);
// Define message
Message m = new MimeMessage(s);
// setting message attributes
try {
m.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
InternetAddress f_addr=new InternetAddress(from);
f_addr.setPersonal(personalName);
m.setFrom(f_addr);
m.setSubject(subject);
m.setSentDate(new Date());
m.setContent(msg,"text/plain");
m.saveChanges();
// send message
Transport.send(m);
Message was edited by:
Aradhana -
Java mail api: SendFailedException when trying to send Mail via SMTP
Hello,
I'm trying to send a mail via java mail api using a server that requires smtp authentication.
I'm currently using the following code:
protocol = "smtp";
host = "auth.smtp.profimailer.de";
port = 25;
String from="[email protected]";
String to="[email protected]";
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Authenticator auth = new PopupAuthenticator();
session=Session.getInstance(props,auth);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from,"[email protected]"));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to,"ToName"));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
Transport.send(message);
static class PopupAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("e12345676", "mypass");
}When trying to run this code, I get the following exception:
D:\eclipse30RC1\workspace\ClassifyIt\bin>java -cp .;../lib/javamail.jar de.jwannenmacher.classify.TestMail > test.txt
javax.mail.SendFailedException: Send failed;
nested exception is:
javax.mail.SendFailedException: Sender "[email protected]" <jens
@jens-wannenmacher.de> was rejected: 501
at javax.mail.Transport.doSend(Transport.java:223)
at javax.mail.Transport.send(Transport.java:92)
at de.jwannenmacher.mail.pop3client.POP3Client.getAllNewMessages(POP3Cli
ent.java:176)
at de.jwannenmacher.classify.TestMail.main(TestMail.java:22)
Any suggestions on this?
Thanks and best regards,
JensHi,
yes smtp is a standard and I think you could use this with almost every smtp server.
If your smtp server doesn't require authentication you can access it without an authenticator
I think...
Best regards,
Jens -
Maximum retries for sending mail ( java mail api )
Hi,
How can I set the property "maximum retries for sending mail" for my smtp through java mail api ?
Is there any property that I need to set in the Javamail session or any other way out ?
Thanks.That's a server property. You would set that in your server configuration. JavaMail is for sending and receiving mail, not for controlling mail servers.
-
Failed to build Java Mail API 1.4.5 with maven-3.0.4
Hi,
I am trying to build Java Mail 1.4.5 with Maven-3.0.4 using default settings of maven.
It is getting failed to build due to following errors -
[ERROR] COMPILATION ERROR :
[INFO] -----------------------------------------------------------
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[210,37] cannot find symbol
symbol : variable Version
location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[369,47] cannot find symbol
symbol : variable Version
location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[913,29] cannot find symbol
symbol : variable Version
location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[916,29] cannot find symbol
symbol : variable Version
location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[919,29] cannot find symbol
symbol : variable Version
location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[922,29] cannot find symbol
symbol : variable Version
location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[925,29] cannot find symbol
symbol : variable Version
location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[928,29] cannot find symbol
symbol : variable Version
location: class javax.mail.Session
[INFO] 8 errors
[INFO] -----------------------------------------------------------
[INFO] ----------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ----------------------------------------------------------------------
[INFO] Total time: 1:51.197s
[INFO] Finished at: Tue Jan 08 13:06:01 IST 2013
[INFO] Final Memory: 12M/67M
[INFO] ----------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.
3.2:compile (default-compile) on project javax.mail: Compilation failure: Compil
ation failure:
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[210,37] cannot find symbol
[ERROR] symbol : variable Version
[ERROR] location: class javax.mail.Session
[ERROR]\Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[369,47] cannot find symbol
[ERROR] symbol : variable Version
[ERROR] location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[913,29] cannot find symbol
[ERROR] symbol : variable Version
[ERROR] location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[916,29] cannot find symbol
[ERROR] symbol : variable Version
[ERROR] location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[919,29] cannot find symbol
[ERROR] symbol : variable Version
[ERROR] location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[922,29] cannot find symbol
[ERROR] symbol : variable Version
[ERROR] location: class javax.mail.Session
[ERROR]\Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[925,29] cannot find symbol
[ERROR] symbol : variable Version
[ERROR] location: class javax.mail.Session
[ERROR] \Workarea\mySourceData\src\Mail\mail\src\main\java\javax\mail\Session.java:[928,29] cannot find symbol
[ERROR] symbol : variable Version
[ERROR] location: class javax.mail.Session
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on
project javax.mail: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
ild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
352)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation fail
ure
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompiler
Mojo.java:656)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:209)
... 19 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExceptionSame issue I am facing when I am trying to build Java Mail with netbeans - 7.2.1, it getting failed with same version issue in Session.java class.
How can I set this Version in Session.java class to get rid of this error?
If we can use nexus repository then please let me know how to set this.
Thanks,
Neelam SharmaI answered this question here:
http://stackoverflow.com/questions/14217596/failed-to-build-java-mail-api-1-4-5-with-maven-3-0-4/14288418#14288418 -
Problem with sending mail throgh java mail api
hi folks,
We are having problem regarding sending mail using java mail api.
we are using msgsendsample.java file from demo folder contained in javamail-1.3.3_01 folder.
we are using following command at dos prompt.:
java msgsendsample [email protected] [email protected] smtp.mail.yahoo.com false
It gives following Exception:
--Exception handling in msgsendsample.java
com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required - for hel
p go to http://help.yahoo.com/help/us/mail/pop/pop-11.html
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
333) at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:906)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:535)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at msgsendsample.main(msgsendsample.java:93)
** ValidUnsent Addresses
[email protected]
Thanking in Advance...
Please give us guidance to any alternate solution if exists.hi
the smtp server u are using should allow u to send mail to other smtp server like if u r sending mail to yahoo account u have to use yahoo smtp server only .....
bye -
Work around for iPhone POP3 Server Problems
A common problem that people seem to be having (checking other discussion forums) is that once an e-mail account is active on the iPhone, they have real problems sending e-mails for that account from their Mac or PC. I had that problem too. After some technical research, here is the cause:
1. Your e-mail service provider's POP3 server runs a simple UNIX protocol that only allows a single client to access it at a time - i.e. the PC/MAC mail client or the mobile device, but never both at the same time.
2. Provided that the PC/MAC mail client and the mobile mail client don't access the POP3 server too often and that they are quick, then it's not a problem.
3. If they check too often or are slow to release the POP3 server, then obviously the probability of clashes and lockouts increases.
4. There is quite a bit of discussion on the web that points to the iPhone not releasing the POP3 server quickly - in fact it can hang on for a long time
5. This results in the PC e-mail client reporting incorrect password constantly, driving you nuts (that's tech talk)
BUT HERE IS A SIMPLE, FLAWLESS WORKAROUND:
1. You create a new e-mail account for myself (either with your existing provider, or a free provider like gmail)
2. You configure your main e-mail account to send a copy of incoming e-mails to that new e-mail account (whilst retaining a copy for the main account) - most paid service providers will let you do this.
3. You do NOT set that new account up on your PC/MAC e-mail client, only on your iPhone. When you do that, in the POP Account Information" panel, you use your main e-mail address and not your new, duplicate address. In the "Incoming MAil Server" section of the set up, you use the username/password of the new, duplicate account. That way you receive stuff from that account, but when you send, it comes from your main account. Cool huh?!
4. That way, it doesn't matter how long the iPhone hangs on to the account - it's simply a duplicate account that no other client comes along to access. Ever.
5. Outgoing mail is not a problem, since this fault does not exist with the SMTP server protocol, only with the incoming POP3 server.
ENJOY!Hi Jeff
Well Jeff, I must bow my head in shame. I've had this love and hate relationship with Adobe for many years, and don't even mention the name Matrox in the same sentence or I will go off the wall! However, this is apparently operator error. Man do I feel like an idiot! (Sorry Adobe for being so nasty with you. Peace!)
The bottom line is, Black Magic does not, and has never claimed to support Encore.
If I would of read all of the installation instructions I would of seen that. Here is a list of the 3rd party software that the Intensity pro does support. I've seen this list several times, but never really looked for Encore in that list of apps. I guess I just assumed that if it worked in Premiere Pro, that it would also work in Encore especially Since Encore is Married to Premiere Pro. Then the other thing that helps to confuse the issue is that Black Magic is one of the external options which show up inside Encores Audio/Video output preferences. One would just assume if it showed up there, that it should work, but that's not the case.
Third Party Software Support
• Apple Final Cut Pro 7
• Apple Motion 4
• Apple Soundtrack Pro 3
• Apple Color 1.5
• Apple DVD Studio Pro 4
• Apple Final Cut Pro 6.0.5
• Apple Motion 3.0.2
• Apple Soundtrack Pro 2.0.2
• Apple Color 1.0.2
• Apple DVD Studio Pro 4.2.1
• Adobe After Effects CS4
• Adobe Photoshop CS4
• Adobe Premiere Pro CS3 v3.2
• Adobe After Effects CS3 8.0.2
• Adobe Photoshop CS3 10.0.1
• Steinberg Nuendo 3.2
• Digidesign Pro Tools 8
The Intensity pro works fine for an HDMI output device inside of Final Cut though, sure with it would would work in Encore. I called and spoke with Black Magic Support, they confirmed that I was a idiot. Oh well, there's always a chance I may not be wrong, got to check it out! LOL -
SSL Portal for IMAP, POP3, SMTP?
Hello,
is it possible to offer with an UAG SSL Portal a preauthentication for IMAP, POP3 and SMTP?
If yes, any How to's out there?
Edit: I know that TMG is able to offer that but is there preauthentication used?
Grüße/Regards, Jens KleinHi,
No, UAG does not support (as in does not work) any other ports than 80 and 443.
Hth,
Lutz
Maybe you are looking for
-
I'm working on a group of files(25-28) at a time. I have to save each one as a photoshop .raw file and change the first character of the file name. the rest of the file name must remain the same. I then close the original file with no changes. I tri
-
I can't find Journey's new song After All These Years on Itunes . . . Help.
-
How to import just a folder?
When I try to import photos from a folder of my drive d:\, I have the "Navigator" on top, then "Folders". When I click on "Folders", I get a list of "Devices", then of "Files" as they are called, but in fact it's a list of drives, among them d:\. Now
-
Custom Sequence Resolution in FCPX 10.1?
I've been told that FCPX 10.1 does custom timeline sequence resolutions, is there truth to this? I am composing a 3:1 ratio video. Thanks for any advice! -Brett
-
Plan to apply patch SAP_JTECHS 7.00
Hi I am planing to apply patch SAP_JTECHS 7.00 SP18 patch level 13 for Note.1416047. Current support package version SAP_JTECHS 7.00 SP13 patch level 0 JSPM 7.00 SP13 patch level 0 I would like to know how to apply patch. I assume to do below. 1.u