منتديات احباب عرب  

العودة   منتديات احباب عرب > القسم التقني > سات 2017 ـ sat 2017

probleme java mail

salut j'ai un application java qui envoyer un messsage a un client voila le code SendMailUsingAuthentication.java كود: import javax.mail.*;

إضافة رد
 
LinkBack أدوات الموضوع انواع عرض الموضوع
  #1  
قديم 07-14-2012, 01:42 AM
الصورة الرمزية رشاء احمد
رشاء احمد غير متواجد حالياً
 
تاريخ التسجيل: Mar 2010
المشاركات: 64,439
معدل تقييم المستوى: 82
رشاء احمد has much to be proud ofرشاء احمد has much to be proud ofرشاء احمد has much to be proud ofرشاء احمد has much to be proud ofرشاء احمد has much to be proud ofرشاء احمد has much to be proud ofرشاء احمد has much to be proud ofرشاء احمد has much to be proud of
موضوع منقول probleme java mail

<div><div align="center"><b>salut

j'ai un application java qui envoyer un messsage a un client

voila le code

SendMailUsingAuthentication.java
كود:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class SendMailUsingAuthentication
{
private static final String SMTP_HOST_NAME = "smtp.gmail.com"; // for google
private static final String SMTP_AUTH_USER = "user mail"; // Username
private static final String SMTP_AUTH_PWD = "password"; // Password


// Add List of Email address to who email needs to be sent to
public void postMail( String recipients[ ], String subject,
String message , String from) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");

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[i]);
**
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
**


/**
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator
{

@Override
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
**
**
**
MainForm.java
<div style="margin:20px; margin-top:5px"> كود:
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;


/**
*
* @author KAI
*/
public class MainForm extends javax.swing.JFrame {
private static String emailMsgTxt = "";
private static String emailSubjectTxt = "";
private static String emailFromAddress = "";

// Add List of Email address to who email needs to be sent to
private static String[] emailList = new String[10];

/** Creates new form MainForm */
public MainForm() {
initComponents();
**
public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
{
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", "smtp.gmail.com");

// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
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[i]);
**
msg.setRecipients(Message.RecipientType.TO, addressTo);


// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
**
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
txto = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
txtsubject = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtfrom = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
txtmessage = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

jPanel2.setBorder(javax.swing.BorderFactory.create EtchedBorder());

jButton1.setText("send Mail");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
**
**);

jLabel1.setText("To");

txto.setText("");

jLabel2.setText("Subject");

txtsubject.setText("");

jLabel3.setText("From:");

txtfrom.setEditable(false);
txtfrom.setText("[email protected]");

jLabel4.setText("Message:");

txtmessage.setColumns(20);
txtmessage.setRows(5);
txtmessage.setText("");
jScrollPane1.setViewportView(txtmessage);

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(jLabel1)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtfrom, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
.addComponent(txtsubject, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
.addComponent(txto, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
.addComponent(jScrollPane1)))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(158, 158, 158)
.addComponent(jButton1)))
.addContainerGap(40, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(jPanel2Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtsubject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtfrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE))
);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(39, 39, 39)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(23, Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);

pack();
**//

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

emailMsgTxt = txtmessage.getText();
emailSubjectTxt = txtsubject.getText();
emailFromAddress = txtfrom.getText();

// Add List of Email address to who email needs to be sent to
StringBuffer sb=new StringBuffer(txto.getText());
StringTokenizer st=new StringTokenizer(txto.getText());
int i=0;
while(st.hasMoreTokens()){
emailList[i]=st.nextToken(",");
System.err.println(emailList[i]);
i++;
**

String emailReceipeint[]=new String[i];
for(int j=0;j

المواضيع المتشابهه:

رد مع اقتباس
إضافة رد


الذين يشاهدون محتوى الموضوع الآن : 1 ( الأعضاء 0 والزوار 1)
 
أدوات الموضوع
انواع عرض الموضوع

تعليمات المشاركة
لا تستطيع إضافة مواضيع جديدة
لا تستطيع الرد على المواضيع
لا تستطيع إرفاق ملفات
لا تستطيع تعديل مشاركاتك

BB code is متاحة
كود [IMG] متاحة
كود HTML معطلة
Trackbacks are متاحة
Pingbacks are متاحة
Refbacks are متاحة


Privacy Policy سياسة الخصوصية |

Sitemap

الساعة الآن 12:20 PM.


Powered by vBulletin™ Version 3.8.7
Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.
SEO by vBSEO