Problem while sending a mail with smtp and ssl
Hi all,
I am new to java mail . I have downloaded one java program to send the mail. I have configured smt and port address.And my System firewall is also in off mode
Still i am unable to send the mail
The following code is my program import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.URLName;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.sun.mail.smtp.SMTPSSLTransport;
To use this program, change values for the following three constants,
SMTP_HOST_NAME -- Has your SMTP Host Name
SMTP_AUTH_USER -- Has your SMTP Authentication UserName
SMTP_AUTH_PWD -- Has your SMTP Authentication Password
Next change values for fields
emailMsgTxt -- Message Text for the Email
emailSubjectTxt -- Subject for email
emailFromAddress -- Email Address whose name will appears as "from" address
Next change value for "emailList".
This String array has List of all Email Addresses to Email Email needs to be sent to.
Next to run the program, execute it as follows,
SendMailUsingAuthentication authProg = new SendMailUsingAuthentication();
public class SendMailUsingAuthentication
//private static final String SMTP_HOST_NAME = "smtp.mail.yahoo.com";
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final String SMTP_AUTH_USER = "admijn.ramd";
private static final String SMTP_AUTH_PWD = "hairamu";
private static final int SMTP_PORT = 465;
private static final String emailMsgTxt = "Online Order Confirmation Message. Also include the Tracking Number.";
private static final String emailSubjectTxt = "Order Confirmation Subject";
private static final String emailFromAddress = "[email protected]";
// Add List of Email address to who email needs to be sent to
private static final String[] emailList = {"[email protected]", "[email protected]"};
public static void main(String args[]) throws Exception
SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
public void postMail( String recipients[ ], String subject,
String message , String from)
try{
boolean debug = false;
//Set the host smtp address
// Set the host smtp address
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setText(message);
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}catch (MessagingException e) {
// TODO: handle exception
e.printStackTrace();
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
private class SMTPAuthenticator extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
try{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
System.out.println("username "+ username+" Password"+password);
return new PasswordAuthentication(username, password);
}catch (Exception e) {
return null;
And i am getting the following exceptions
javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1611)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1369)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:310)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at com.FutureSoft.org.SendingMail.SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:123)
at com.FutureSoft.org.SendingMail.SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:70)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:88)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1589)
... 9 more
hi neuro11
the following code is for sending mail its is working fine in my system, just change the
SMTP_AUTH_USER = "tina.numi"; with u r email user name
SMTP_AUTH_PWD = "abdcde"; u r gmail password
emailFromAddress = "[email protected]"; ur gmail addres
emailList = {"[email protected]"}; receipient list .
and u must sure that u r internet is on and firewall should be off . some times firewall restricts you to communicate with gmail port number
Please make u r firewall off and source code is
package com.FutureSoft.org.SendingMail;
Some SMTP servers require a username and password authentication before you
can use their Server for Sending mail. This is most common with couple
of ISP's who provide SMTP Address to Send Mail.
This Program gives any example on how to do SMTP Authentication
(User and Password verification)
This is a free source code and is provided as it is without any warranties and
it can be used in any your code for free.
Author : Sudhir Ancha
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.URLName;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.sun.mail.smtp.SMTPSSLTransport;
To use this program, change values for the following three constants,
SMTP_HOST_NAME -- Has your SMTP Host Name
SMTP_AUTH_USER -- Has your SMTP Authentication UserName
SMTP_AUTH_PWD -- Has your SMTP Authentication Password
Next change values for fields
emailMsgTxt -- Message Text for the Email
emailSubjectTxt -- Subject for email
emailFromAddress -- Email Address whose name will appears as "from" address
Next change value for "emailList".
This String array has List of all Email Addresses to Email Email needs to be sent to.
Next to run the program, execute it as follows,
SendMailUsingAuthentication authProg = new SendMailUsingAuthentication();
public class SendMailUsingAuthentication
//private static final String SMTP_HOST_NAME = "smtp.mail.yahoo.com";
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final String SMTP_AUTH_USER = "tina.numi";// gmail username
private static final String SMTP_AUTH_PWD = "abdcde";// gmail password
private static final int SMTP_PORT = 465;
private static final String emailMsgTxt = "Online Order Confirmation Message. Also include the Tracking Number.";
private static final String emailSubjectTxt = "Order Confirmation Subject";
private static final String emailFromAddress = "[email protected]";// gmail id
// Add List of Email address to who email needs to be sent to
private static final String[] emailList = {"[email protected]"};
public static void main(String args[]) throws Exception
SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
public void postMail( String recipients[ ], String subject,
String message , String from)
try{
boolean debug = false;
//Set the host smtp address
// Set the host smtp address
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setText(message);
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport t = session.getTransport("smtps");
try {
t.connect(SMTP_HOST_NAME, SMTP_AUTH_USER, SMTP_AUTH_PWD);
t.sendMessage(msg, msg.getAllRecipients());
catch(Exception e){}
finally
t.close();
}catch (MessagingException e) {
// TODO: handle exception
e.printStackTrace();
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
private class SMTPAuthenticator extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
try{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
System.out.println("username "+ username+" Password"+password);
return new PasswordAuthentication(username, password);
}catch (Exception e) {
return null;
try this . all the best
Similar Messages
-
Problem sending mail with SMTP and SSL
Hi,
I am trying to send mail using JavaMail 1.4/jdk1.5 using ssl. I save the certificate by going into IE and exporting the certificate and added the certificate using the keytool to ${JAVA_HOME}/jre/lib/security/cacerts.I have also added this in the code using
System.setProperty("javax.net.ssl.trustStore","${JAVA_HOME}/jre/lib/security/cacerts");But I am still getting the following error.
DEBUG SMTP: trying to connect to host "XXXX", port 465, isSSL true
DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
Exception in thread "main" javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at glycomics.common.util.SendMailUsingAuthentication.postMail(Unknown Source)
at glycomics.common.util.SendMailUsingAuthentication.main(Unknown Source)
Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:166)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1518)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1485)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1468)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1394)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:86)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
... 5 more
Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:56)
at sun.security.validator.Validator.getInstance(Validator.java:146)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:105)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:167)
at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:841)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:818)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1030)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:678)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
... 10 more
Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:183)
at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:103)
at java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:87)
at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:54)Has anybody faced similar problem??Any suggestions??
TIA
M
Message was edited by:
c@de-m@nkeySee SSLNOTES.txt and the JavaMail FAQ for debugging hints.
If you turn on all the debugging output and still can't figure it out,
you'll probably need to ask in some Java security forum. The
problem is occurring when making the connection using SSLSocket,
before any JavaMail code comes into play. -
Excel 2007 Problems while sending E-Mail with Excel Attachment
Hello all,
i wrote a small WD application for uploading a file and sending this file
vie e-mail to some recipients.
I'm using class "cl_document_bcs". No problem with ".doc", ".pdf", also no problem
with ".xls" files generated by old Excel version. But when generating an .xls document with
Excel 2007, the attached file is not readable (just non usable signs).
For attaching the .xls file i use:
TRY.
lr_attachment = cl_document_bcs=>create_document(
i_type = lv_filetype " --> 'XLS'
i_subject = 'excel document'
i_hex = lt_file_solix
CATCH cx_document_bcs .
ENDTRY.
Are there any restrictions regarding Excel 2007?
The data element of i_type is just char3, so XLSX
wouldn't be possible.hello Christopher Linke ,
if you Programatically generation a excel file and you have 2007 version you can use OLE automation to save file as .xls i.e. a 2003 work book ..
if you have a excel file ready and you just want to send it across the you will have to convert the xlsx to xls and then send it you can do this as well using OLE automation
(in 2007 in SAVE AS option you can save it excel 97 2003 workbook)
Edited by: Anup Deshmukh on Mar 3, 2010 3:38 PM -
Hey. I have problems to send e-mail with Mail. The problems is I need to un active ssl ,... but when I do this,... automatically,. its active again????. Whta can i do
Try posting this in the 10.7 Mail forum. You'll get more help there.
DALE -
Problem while sending the mail from sap
Hi experts,
I am facing some problem while sending mail from sap to external mail.
this is th code i am using but it is not working. plz check and tell me.
REPORT ZMAIL_DEMO.
data: maildata type sodocchgi1.
data: mailtxt type table of solisti1 with header line.
data: mailrec type table of somlrec90 with header line.
start-of-selection.
break-point.
clear: maildata, mailtxt, mailrec.
refresh: mailtxt, mailrec.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test'.
maildata-obj_langu = sy-langu.
mailtxt-line = 'This is a test'.
append mailtxt.
mailrec-receiver = 'SOME MAIL ID'.
mailrec-rec_type = 'U'.
append mailrec.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type = 'RAW'
put_in_outbox = 'X'
tables
object_header = mailtxt
object_content = mailtxt
receivers = mailrec
exceptions
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
if sy-subrc = 0. "( did not receive any mail) *
write : 'mail sent'.
endif.Hi,
Please check with the following code.
TABLES: KNA1.
data for send function
DATA DOC_DATA LIKE SODOCCHGI1.
DATA OBJECT_ID LIKE SOODK.
DATA OBJCONT LIKE SOLI OCCURS 10 WITH HEADER LINE.
DATA RECEIVER LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE.
SELECT * FROM KNA1 WHERE ANRED LIKE 'C%'.
WRITE:/ KNA1-KUNNR, KNA1-ANRED.
send data internal table
CONCATENATE KNA1-KUNNR KNA1-ANRED
INTO OBJCONT-LINE SEPARATED BY SPACE.
APPEND OBJCONT.
ENDSELECT.
insert receiver (sap name)
REFRESH RECEIVER.
CLEAR RECEIVER.
MOVE: 'any_email'_ TO RECEIVER-RECEIVER, " SY-UNAME
'X' TO RECEIVER-EXPRESS,
'U' TO RECEIVER-REC_TYPE.
APPEND RECEIVER.
insert mail description
WRITE 'Sending a mail through abap'
TO DOC_DATA-OBJ_DESCR.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_DATA
IMPORTING
NEW_OBJECT_ID = OBJECT_ID
TABLES
OBJECT_CONTENT = OBJCONT
RECEIVERS = RECEIVER
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8. -
Error while sending a mail with pdf attachment
Hai
I am sending mail with an attachment of PDF document. While sending I am getting
javax.activation.UnsupportedDataTypeException: application/pdf
This is my code
public static void setByteArrayAsAttachment(Message msg, byte[] attach)
throws MessagingException {
MimeBodyPart p1 = new MimeBodyPart();
ByteArrayDataSource byteStr = new ByteArrayDataSource(attach,"application/pdf");
p1.setContent(byteStr,"application/pdf");
Multipart mp = new MimeMultipart();
mp.addBodyPart(p1);
msg.setContent(mp);
Can one one help me on this...
Thanks
Jithesh PMChange
p1.setContent(byteStr,"application/pdf");
to
p1.setDataHandler(new DataHandler(byteStr)); -
Problem with EXCEL format while sending a mail with excel attachment
Hi,
I'm trying to send a report through mail as an excel attchment. But though I get all the details in the attachmnet format in excel is not proper. It's in a very hapazard way. I tried putting control break statements after each record then also though there is slight betterment it's not ok. If I send the same thing as a pdf attachment it's perfect. May I know what else i need to do for excel.....? I tried compressing and then sending no luck......
I'm in version 4.6c.....
Thanks in advance....Hi,
Just check out this..
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
aedat(8) TYPE c,
matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM data_retrieval.
Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
*END-OF-SELECTION
END-OF-SELECTION.
Populate message body text
perform populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
'Example .xls documnet attachment'
'XLS'
'filename'
changing gd_error
gd_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
ENDFORM. " DATA_RETRIEVAL
*& Form BUILD_XLS_DATA_TABLE
Build data table for .xls document
FORM build_xls_data_table.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
class cl_abap_char_utilities definition load.
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
INTO it_attach SEPARATED BY space.
APPEND it_attach.
LOOP AT it_ekpo INTO wa_charekpo.
CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
wa_charekpo-aedat wa_charekpo-matnr
INTO it_attach SEPARATED BY space.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
Instructs mail send program for SAPCONNECT to send email.
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
*& Form POPULATE_EMAIL_MESSAGE_BODY
Populate message body text
form populate_email_message_body.
REFRESH it_message.
it_message = 'This mail is scheduled automatically and excel file is
attached for your reference'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY
Regards,
Sriram.
PS: Reward Points if it is useful. -
Facing problem while sending e-mail
my code runs on a windows server on my machine but as i upload the same class file to the linux machine it does not work.
As there is no error generation go cant get the exact problem..
See my code below if u could help me...
public static String myemail = "[email protected]", //username
mypassword = "*************", //password
myhost = "smtp.abc.com", // smtp address
myport = "234", // port address
mysubject = "Hello",
mytext = "this is just a test mail";
public String mail(String recp)
Properties pro = new Properties();
pro.put("mail.smtp.user", myemail);
pro.put("mail.smtp.host", myhost);
pro.put("mail.smtp.port", myport);
pro.put("mail.smtp.starttls.enable","true");
pro.put("mail.smtp.auth", "true");
pro.put("mail.smtp.debug", "true");
pro.put("mail.smtp.socketFactory.port",myport);
SecurityManager security = System.getSecurityManager();
try
Authenticator authen = new SMTPConfig();
Session session = Session.getInstance(pro, authen);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText(mytext);
msg.setSubject(mysubject);
msg.setFrom(new InternetAddress(myemail));
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress(recp));
Transport.send(msg);
catch (Exception ex)
ex.printStackTrace();
return null;
private class SMTPConfig extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
return new PasswordAuthentication(myemail, mypassword);
}The whole application is running on a dedicated server which is in LINUX OS and when i code on WINDOWS and upload on the server
It works on my machine but when uploaded it doesn't...
Its a servlet which is running some form data insertion in table along with the sending mail thing...
as the data is inserted a mail is sent to the recipient...
Initially it stored the data nut no mail is sent..
Tat is exac "No error generation"
but when i caught the exception and tried to display on a page.... it shows the SMTP address an PORT address not found... No Route to Host...
i.e noroutetohostexception error..
Currently the same thing works on my WINDOWS machine but doesn't work when uploaded to the server...
Can u help me in that -
Problem while sending e-mail from SAP
Hi,
I need to modify customized report, my problem is i need to download as .XLS file as well i need to send as an attachment to e-mail. If i select with NO-Delimeter the attachment comming as .TXT file and if i select any delimeter that occupying one cell in .XLS file.
Can anyone help me out in this.
Thanks,
YogeshHi Yogesh,
Refer the following code as pointer to sending email with attachment.
REPORT ZSAMPL_001 .
INCLUDE ZINCLUDE_01.
DATA
DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.
DATA : file_name TYPE string.
data : path like PCFILE-PATH.
data : extension(5) type c.
data : name(100) type c.
SELECTION SCREEN
PARAMETERS : receiver TYPE somlreci1-receiver lower case.
PARAMETERS : p_file LIKE rlgrap-filename
OBLIGATORY.
AT SELECTION SCREEN
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CLEAR p_file.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_file.
START-OF-SELECTION
START-OF-SELECTION.
PERFORM ml_customize USING 'Tst' 'Testing'.
PERFORM ml_addrecp USING receiver 'U'.
PERFORM upl.
PERFORM doconv TABLES itab objbin.
PERFORM ml_prepare USING 'X' extension name.
PERFORM ml_dosend.
SUBMIT rsconn01
WITH mode EQ 'INT'
AND RETURN.
FORM
FORM upl.
file_name = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_name
filetype = 'BIN'
TABLES
data_tab = itab
EXCEPTIONS
*file_open_error = 1
*file_read_error = 2
*no_batch = 3
*gui_refuse_filetransfer = 4
*invalid_type = 5
*no_authority = 6
*unknown_error = 7
*bad_data_format = 8
*header_not_allowed = 9
*separator_not_allowed = 10
*header_too_long = 11
*unknown_dp_error = 12
*access_denied = 13
*dp_out_of_memory = 14
*disk_full = 15
*dp_timeout = 16
*OTHERS = 17.
path = file_name.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
CHECK_DOS_FORMAT =
IMPORTING
DRIVE =
EXTENSION = extension
NAME = name
NAME_WITH_EXT =
PATH =
EXCEPTIONS
INVALID_DRIVE = 1
INVALID_EXTENSION = 2
INVALID_NAME = 3
INVALID_PATH = 4
OTHERS = 5
ENDFORM. "upl
***INCLUDE ZINCLUDE_01 .
Data
tables crmrfcpar.
DATA: docdata LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objhex LIKE solix OCCURS 10 WITH HEADER LINE,
reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
DATA: tab_lines TYPE i,
doc_size TYPE i,
att_type LIKE soodk-objtp.
DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.
data v_rfcdest LIKE crmrfcpar-rfcdest.
FORM
FORM ml_customize USING objname objdesc.
Clear Variables
CLEAR docdata.
REFRESH objpack.
CLEAR objpack.
REFRESH objhead.
REFRESH objtxt.
CLEAR objtxt.
REFRESH objbin.
CLEAR objbin.
REFRESH objhex.
CLEAR objhex.
REFRESH reclist.
CLEAR reclist.
REFRESH listobject.
CLEAR listobject.
CLEAR tab_lines.
CLEAR doc_size.
CLEAR att_type.
Set Variables
docdata-obj_name = objname.
docdata-obj_descr = objdesc.
ENDFORM. "ml_customize
FORM
FORM ml_addrecp USING preceiver prec_type.
CLEAR reclist.
reclist-receiver = preceiver.
reclist-rec_type = prec_type.
APPEND reclist.
ENDFORM. "ml_customize
FORM
FORM ml_addtxt USING ptxt.
CLEAR objtxt.
objtxt = ptxt.
APPEND objtxt.
ENDFORM. "ml_customize
FORM
FORM ml_prepare USING bypassmemory whatatt_type whatname.
IF bypassmemory = ''.
Fetch List From Memory
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'LIST_FROM_MEMORY'.
ENDIF.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
COMPRESSED_SIZE =
TABLES
in = listobject
out = objbin
EXCEPTIONS
OTHERS = 1
IF sy-subrc <> 0.
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'TABLE_COMPRESS'.
ENDIF.
ENDIF.
Header Data
Already Done Thru FM
Main Text
Already Done Thru FM
Packing Info For Text Data
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'TXT'.
APPEND objpack.
Packing Info Attachment
att_type = whatatt_type..
DESCRIBE TABLE objbin LINES tab_lines.
READ TABLE objbin INDEX tab_lines.
objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = att_type.
objpack-obj_name = 'ATTACHMENT'.
objpack-obj_descr = whatname.
APPEND objpack.
Receiver List
Already done thru fm
ENDFORM. "ml_prepare
FORM
FORM ml_dosend.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = 'X'
commit_work = 'X' "used from rel. 6.10
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
CONTENTS_HEX = objhex
OBJECT_PARA =
object_parb =
receivers = reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8
IF sy-subrc <> 0.
MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
WITH docdata-obj_name.
ENDIF.
ENDFORM. "ml_customize
FORM
FORM ml_spooltopdf USING whatspoolid.
DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.
Call Function
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = whatspoolid
TABLES
pdf = pdf
EXCEPTIONS
err_no_otf_spooljob = 1
OTHERS = 12.
Convert
PERFORM doconv TABLES pdf objbin.
ENDFORM. "ml_spooltopdf
FORM
FORM doconv TABLES
mypdf STRUCTURE tline
outbin STRUCTURE solisti1.
Data
DATA : pos TYPE i.
DATA : len TYPE i.
Loop And Put Data
LOOP AT mypdf.
pos = 255 - len.
IF pos > 134. "length of pdf_table
pos = 134.
ENDIF.
outbin+len = mypdf(pos).
len = len + pos.
IF len = 255. "length of out (contents_bin)
APPEND outbin.
CLEAR: outbin, len.
IF pos < 134.
outbin = mypdf+pos.
len = 134 - pos.
ENDIF.
ENDIF.
ENDLOOP.
IF len > 0.
APPEND outbin.
ENDIF.
ENDFORM. "doconv
FORM
FORM ml_saveforbp USING jobname jobcount.
Data
*data : yhead like yhrt_bp_head.
*DATA : ydocdata LIKE yhrt_bp_docdata,
*yobjtxt LIKE yhrt_bp_objtxt OCCURS 0 WITH HEADER LINE,
*yreclist LIKE yhrt_bp_reclist OCCURS 0 WITH HEADER LINE.
*DATA : seqnr TYPE i.
Head
*yhead-jobname = jobname.
*yhead-jobcount = jobcount..
*MODIFY yhrt_bp_head FROM yhead.
Doc Data
*ydocdata-jobname = jobname.
*ydocdata-jobcount = jobcount.
*MOVE-CORRESPONDING docdata TO ydocdata.
*MODIFY yhrt_bp_docdata FROM ydocdata.
Objtxt
*seqnr = 0.
*LOOP AT objtxt.
*seqnr = seqnr + 1.
*yobjtxt-jobname = jobname.
*yobjtxt-jobcount = jobcount.
*yobjtxt-seqnr = seqnr.
*MOVE-CORRESPONDING objtxt TO yobjtxt.
*MODIFY yhrt_bp_objtxt FROM yobjtxt.
*ENDLOOP.
RecList
*seqnr = 0.
*LOOP AT reclist.
*seqnr = seqnr + 1.
*yreclist-jobname = jobname.
*yreclist-jobcount = jobcount.
*yreclist-seqnr = seqnr.
*MOVE-CORRESPONDING reclist TO yreclist.
*MODIFY yhrt_bp_reclist FROM yreclist.
*ENDLOOP.
ENDFORM. "ml_saveforbp
FORM
FORM ml_fetchfrombp USING jobname jobcount.
*CLEAR docdata.
*REFRESH objtxt.
*REFRESH reclist.
*SELECT SINGLE * FROM yhrt_bp_docdata
*INTO corresponding fields of docdata
*WHERE jobname = jobname
*AND jobcount = jobcount.
*SELECT * FROM yhrt_bp_objtxt
*INTO corresponding fields of TABLE objtxt
*WHERE jobname = jobname
*AND jobcount = jobcount
*ORDER BY seqnr.
*SELECT * FROM yhrt_bp_reclist
*INTO corresponding fields of TABLE reclist
*WHERE jobname = jobname
*AND jobcount = jobcount
*ORDER BY seqnr.
ENDFORM. "ml_fetchfrombp
<b>Please reward points if it helps.</b>
Regards,
Amit Mishra -
Hi,
There is a mail server having domain name 'testdomain.com' in postfix server. There are 200 users
I have created a mail server with the same domain name and created 20 useres. Now I am able to send and receive mails within the users in sun mailing solution. Now I want to send mails to users in postfix server that are having same domain name. For that purpose I have added mailRoutingSmartHost in LDAP.
Even though when I try to send mail to the user in postfix server I am getting the following error:
The mail server responded: 5.1.2 unknown host or domainYes, I have restarted the MTA (messaging server) after modifying the LDAP.
I am using LDAP Schema 2
My mailRoutingSmartHost = 192.168.1.7
192.168.1.7 --- postfix server running on this machine
forward channel = l
channel description =
channel caption =
channel user filter =
dest channel filter =
source channel filter =
channel flags #0 = BIDIRECTIONAL MULTIPLE IMMNONURGENT NOSERVICEALL
channel flags #1 = NOSMTP DEFAULT
channel flags #2 = COPYSENDPOST COPYWARNPOST POSTHEADONLY HEADERINC NOEXPROUTE
channel flags #3 = NOLOGGING NORESTRICTED RETAINSECURITYMULTIPARTS
channel flags #4 = EIGHTBIT HEADERKEEPORDER NOHEADERREAD RULES
channel flags #5 = TRUNCATESMTPLONGLINES
channel flags #6 = LOCALUSER REPORTNOTARY
channel flags #7 = NOSWITCHCHANNEL NOREMOTEHOST DATEFOUR DAYOFWEEK
channel flags #8 = NODEFRAGMENT EXQUOTA REVERSE NOCONVERT_OCTET_STREAM
channel flags #9 = NOTHURMAN INTERPRETENCODING USEINTERMEDIATE RECEIVEDFROM VALIDATELOCALSYSTEM NOTURN
defaulthost = avesthagen.com avesthagen.com
linelength = 1023
channel env addr type = SOURCEROUTE
channel hdr addr type = SOURCEROUTE
channel official host = sunmail.avesthagen.com
channel queue 0 name = LOCAL_POOL
channel queue 1 name = LOCAL_POOL
channel queue 2 name = LOCAL_POOL
channel queue 3 name = LOCAL_POOL
channel after params =
channel user name =
urgentnotices = 1 2 4 7
normalnotices = 1 2 4 7
nonurgentnotices = 1 2 4 7
channel rightslist ids =
local behavior flags = %x7
expandchannel =
notificationchannel =
dispositionchannel =
saslswitchchannel =
tlsswitchchannel =
backward channel = l
unique identifier = [email protected]
header forward address = [email protected] (route (sunmail.avesthagen.com,sunmail.avesthagen.com)) (host avesthagen.com)
header reverse address = [email protected]
envelope forw address = [email protected] (route (sunmail.avesthagen.com,sunmail.avesthagen.com)) (host avesthagen.com)
envelope rev address = [email protected] (route (sunmail.avesthagen.com,sunmail.avesthagen.com)) (host avesthagen.com)
name =
mbox = ranga
Extracted address action list:
[email protected]
Extracted 733 address action list:
[email protected]
Address list expansion:
@192.168.1.7:[email protected]
1 expansion total.
Expanded address:
[email protected]
Submitted address list:
Address list error -- 5.1.2 unknown host or domain: [email protected]
Submitted notifications list: -
having problems receiving/sending e mails on ipad, deleted hotmail account and reinstated it. inbox now ok but my folders i.e drawing, deleted, sent etc have disappeared.they still show in my hotmail on my computerand iphone, they contain info i need on my ipad. How do i transfer or obtain these folders on my ipad with the info intact
when you put your mail back onto your iPad did you use the outlook option in the mail settings?
-
Problems while sending mail using java mail
hi all,
the following are the errors i get while sending a mail from my smtp local host-
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class SendEmail
public static void main(String[] args)
System.out.println(args.length);
if (args.length != 6)
System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");
System.exit(1);System.out.println("jj"+args.length);
SendEmail m=new SendEmail();
m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);
public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
boolean debug = false; // change to get more information
String msgText2 = "multipart message";
boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
// set the host
Properties props = new Properties();
props.put("mail.smtp.host",smtphost);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.sendpartial", "true");
Authenticator loAuthenticator = new SMTPAuthenticator();
System.out.println("f");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, loAuthenticator );
session.setDebug(debug);
try
// create a message
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(emailfrom);
msg.setFrom(from);
InternetAddress[] address =
new InternetAddress(emailto)
//InternetAddress ad=new InternetAddress(session);
msg.setRecipients(Message.RecipientType.TO, address);
System.out.println("fc");
msg.setSubject(msgSubject);
System.out.println("fvf");
if(!sendmultipart)
// send a plain text message
msg.setContent(msgText, "text/plain");
System.out.println("fif");
else
System.out.println("felsd");
// send a multipart message// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport transport = session.getTransport("smtp");
transport.connect(smtphost,"[email protected]","xyz");
msg.saveChanges();
System.out.println("fconn");
//transport.sendMessage(msg,msg.getAllRecipients());
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
//Transport.send(msg);
catch(MessagingException mex)
mex.printStackTrace();
return "Email sent to " + emailto;
class SMTPAuthenticator extends Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = "[email protected]";
String password = "xyz";
return new PasswordAuthentication(username, password);
i dont understand what the problem is..inspite of having the right code..
i guess some firewall problem..
can somebody help me please..il be highly obliged..thanks..hi all,
the following are the errors i get while sending a mail from my smtp local host-
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class SendEmail
public static void main(String[] args)
System.out.println(args.length);
if (args.length != 6)
System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");
System.exit(1);System.out.println("jj"+args.length);
SendEmail m=new SendEmail();
m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);
public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
boolean debug = false; // change to get more information
String msgText2 = "multipart message";
boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
// set the host
Properties props = new Properties();
props.put("mail.smtp.host",smtphost);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.sendpartial", "true");
Authenticator loAuthenticator = new SMTPAuthenticator();
System.out.println("f");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, loAuthenticator );
session.setDebug(debug);
try
// create a message
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(emailfrom);
msg.setFrom(from);
InternetAddress[] address =
new InternetAddress(emailto)
//InternetAddress ad=new InternetAddress(session);
msg.setRecipients(Message.RecipientType.TO, address);
System.out.println("fc");
msg.setSubject(msgSubject);
System.out.println("fvf");
if(!sendmultipart)
// send a plain text message
msg.setContent(msgText, "text/plain");
System.out.println("fif");
else
System.out.println("felsd");
// send a multipart message// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport transport = session.getTransport("smtp");
transport.connect(smtphost,"[email protected]","xyz");
msg.saveChanges();
System.out.println("fconn");
//transport.sendMessage(msg,msg.getAllRecipients());
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
//Transport.send(msg);
catch(MessagingException mex)
mex.printStackTrace();
return "Email sent to " + emailto;
class SMTPAuthenticator extends Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = "[email protected]";
String password = "xyz";
return new PasswordAuthentication(username, password);
i dont understand what the problem is..inspite of having the right code..
i guess some firewall problem..
can somebody help me please..il be highly obliged..thanks.. -
Receive a mail with attachment and send it as it is via Mail-receiver
Hi,
we have PI/7.0
I have a scenario with a mail-sender.
I get mails with attachments and depending on the subject I have to send some mails to an other mail-address via mail-receiver-adapter.
My problem is, that I have to send it "as it was" - with all attachments (and the correct attachment names) and the original mail-body.
I tried to check the checkbox "keep attachments": I got all attachments but the original mail-body was now an extra attachment (with the extension .xml).
I don't wanna have this new attachment!
What can I do?
Thanx a lot!
Regards
WolfgangHi,
I think quite simple
message protocol: xipayload
Use Mail package: NO
Keep Attachments: YES
Content encoding: <nothing>
No extra modul
I entered all address-informations (from, to,...) in the fields displayed after the checkbox for "use mail package".
that's all.
regards
Wolfgang -
Send a mail with change history while changing the Routing (T-Code CA02),
Hi All,
I need to send a mail with change history while changing the Routing (T-Code CA02), Please let me know how can implement this scenario.
I am trying to find out any workflow is there for the same but we have workflow for Routing creating and Display, we donu2019t have workflow for change.
Please suggest meu2026u2026u2026u2026
Thanks,
Amjad.Hi All,
I need to send a mail with change history while changing the Routing (T-Code CA02), Please let me know how can implement this scenario.
I am trying to find out any workflow is there for the same but we have workflow for Routing creating and Display, we donu2019t have workflow for change.
Please suggest meu2026u2026u2026u2026
Thanks,
Amjad. -
i am facing problems while openin an application in facebook and other places.when i go to the application,an error shows and firefox closes autmatically either i send error reports or dont.....plz help
Notes:
1) Please use the code tags when posting code or JNLP/HTML. It helps to retain indentation and avoids asterisks and plus sings being interpreted as formatting marks. To do that, select the code/JNLP etc. and click the CODE button seen on the Plain Text tab of the message posting form.
2) That launch file is invalid. You might check it (and the project in general) using JaNeLA.
3) The only place that SimpleSerial class could be, that the JRE would find, is in the root of aeon.jar. Is it actually there?
Maybe you are looking for
-
Time Machine and MacFamilyTree problem
I deleted an item in my MacFamilyTree and when I restore an old update of it to get the info, the restored version includes the latest modified info. Why can I not get the old version without the new modification?
-
ITunes copying from one PC to other PC
Hello!I have a question:how is it possible to copy my iTunes from one PC to the other one?
-
The "WIndows 8.1 explorer slows down gradually" thread.
The (now locked) previous thread was: http://social.technet.microsoft.com/Forums/en-US/f9ab40a8-6681-4c66-bdbd-9de7b2fb021f/action?threadDisplayName=windows-81-gradually-slows-down-after-hours-speed-returns-normal-if-restart I don't know why it is lo
-
Adobe premier pro cc price ?
i have just started to learn video editing, I downloaded the tired and I like it very much. I can't seem to find the cost for the software. DO do I need to sign up the month cloud deal to use this ? Or can I just get the software on its own? does ad
-
Messages open several tabs in Thunderbird, one for each step in the mail exchange
A friend has a new PC with Windows 8. If a message is a reply, when opening the message each step in the mail exchange will open in a different tab in Thunderbird.