Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Alerter that sends the alert to email.
 Post subject: Alerter that sends the alert to email. Post rating: 0   New post Posted: Wed 16 Mar, 2011, 15:58 

User rating: 0
Joined: Tue 18 Jan, 2011, 16:17
Posts: 3
Hi!

How can I add a email alert on the alerter code presented in the forum? Pls. help cuz that is all I need in order for me to keep track with my positions.

Thanks alot! By the way, I am still a NOOB when it comes to JAVA programming, so pls. help me make one for JFOREX.

Thanks again!


 
 Post subject: Re: Alerter that sends the alert to email. Post rating: 0   New post Posted: Fri 18 Mar, 2011, 10:13 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
Hi Arkhos,

please have a look here:
https://en.wikipedia.org/wiki/Javamail

Best, RR.


 
 Post subject: Re: Alerter that sends the alert to email. Post rating: 0   New post Posted: Mon 21 Mar, 2011, 23:12 

User rating: 5
Joined: Fri 22 Oct, 2010, 09:54
Posts: 24
Hi!

You could implement this code snippet, which is sending mail through google smtp.

private class JFXMail implements Callable<Boolean> {
      
      private String smtpserver;
      private String from;
      private String to;
      private String subj;
      private String text;
      
      public JFXMail(String smtpserver, String from, String to, String subj, String text){
         this.smtpserver = smtpserver;
         this.from = from;
         this.to = to;
         this.subj = subj;
         this.text = text;
      }

      private Session getSession() {
         Authenticator authenticator = new Authenticator();

         Properties properties = new Properties();
         properties.setProperty("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserName());
         properties.setProperty("mail.smtp.auth", "true");
         properties.setProperty("mail.smtp.starttls.enable","true");
         properties.setProperty("mail.smtp.socketFactory.port", "465");
         properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
         properties.setProperty("mail.smtp.socketFactory.fallback", "false");
         properties.setProperty("mail.smtp.host", smtpserver);
         properties.setProperty("mail.smtp.port", "465");

         return Session.getInstance(properties, authenticator);
      }

      private class Authenticator extends javax.mail.Authenticator {
         private PasswordAuthentication authentication;

         public Authenticator() {
            String username = "[email protected]";
            String password = "xypassword";
            authentication = new PasswordAuthentication(username, password);
         }

         protected PasswordAuthentication getPasswordAuthentication() {
            return authentication;
         }
      }

      public Boolean call() throws Exception {
         Boolean retVal = false;
         try {
            Message message = new MimeMessage(getSession());

            message.addRecipient(RecipientType.TO, new InternetAddress(to));
            message.addFrom(new InternetAddress[] { new InternetAddress(from) });

            message.setSubject(subj);
            message.setContent(text, "text/plain");

            Transport.send(message);

              
               retVal = true;
           } catch (Exception e) {
              retVal = false;
               throw new JFException(e);
           }
         return retVal;
      }
      
   }


Call JFXMail from your strategy like this:

SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                   JFXMail mail = new JFXMail(smtpserver, from, to, subj, mess);
                   context.executeTask(mail);
                }
            });


regards,
Kirilla


 
 Post subject: Re: Alerter that sends the alert to email. Post rating: 0   New post Posted: Wed 28 Dec, 2011, 21:28 

User rating: 0
Joined: Wed 21 Dec, 2011, 08:05
Posts: 2
Location: DE
ok, sry...problem solved.




---------------------------------------------------------

Hi,

I loosking exactly for such a snippet...how can i call that in my statagy? If i import it i only get Errors

package jforex;

import java.util.*;

import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;


import com.dukascopy.api.*;
import com.dukascopy.api.*;
import com.dukascopy.api.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


@RequiresFullAccess
@Library("C:\\Users\\Andy\\Documents\\JForex\\Strategies\\JFXMail.jar;C:\\Program Files\\Java\\MAil\\javamail-1.4.4\\mail.jar")
public class EMAILtest implements IStrategy {
   private IEngine engine;
   private IConsole console;
   private IHistory history;
   private IContext context;
   private IIndicators indicators;
   private IUserInterface userInterface;
    public String smtpserver = "SMPT";
    public String from = "me";
    public String to = "you";
    public String subj = "sub";
    public String mess   = "mess";
   public void onStart(IContext context) throws JFException {
      this.engine = context.getEngine();
      this.console = context.getConsole();
      this.history = context.getHistory();
      this.context = context;
      this.indicators = context.getIndicators();
      this.userInterface = context.getUserInterface();
                               
                   JFXMail mail = new JFXMail(smtpserver, from, to, subj, mess);
                   context.executeTask(mail);
           

       
   }

   public void onAccount(IAccount account) throws JFException {
   }

   public void onMessage(IMessage message) throws JFException {
   }

   public void onStop() throws JFException {
   }

   public void onTick(Instrument instrument, ITick tick) throws JFException {
   }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }

}



my Jar File is the same as you posted above. Do i have to save it to a special location?


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com