Friday, March 21, 2014

How To Sign In a Jar File

Steps to sign in a jar

1. Generate a private a key

        [path] >keytool -genkey -keystore -alias 
        E.g. C:\Users\chathuryad\Desktop\jarSign>keytool -genkey -keystore testkeystore -alias chathurya


Once you enter the command, it will prompt multiple questions and you have to answer them all. And please remember the password you provided, you need to provide it when you sign a jar


.
2. Then you can sign a jar 

 path>jarsigner -keystore -signedjar   
 E.g. C:\Users\chathuryad\Desktop\jarSign>jarsigner -keystore testkeystore -signedjar S2CBuilder.signed.jar S2CBuilder.jar chathurya





3. Delete files in signed jar. Open signed jar(E.g.: S2CBuilder.signed.jar) by using 7-zip compression tool.











goto META-INF folder and delete BCKEY.SF and BCKEY.DSA files.


Now you are done with jar signing and by double click on the signed jar file, you can execute it.

Wednesday, March 19, 2014

How to install (reuse) a same windows task

    1. Select the task which you want to get a back up.  And click on the Export link



    1. Then export the task as a xml file.
    1. Ten again you should write a .bat file to load this xml file to the Windows task scheduler.

    Your batch file will be something like this:

    @echo off
    echo Importing All Tasks
    echo.
    schtasks /create /RU SYSTEM /TN "php_mail_sender" /XML "C:\wamp\www\TS\php_mail_sender.xml"
    echo.
    echo Importing Done
    echo.
    Pause
    


  1. Then by simply run this batch file you can add this task to your Scheduler.

How to use windows task scheduler to send email

    In here, I'm trying to send a mail as a scheduled task. Now my mail function is work 100% correctly ( See project A). In here you have to follow few steps.

    1. Start -> type Task Scheduler
    2. Select Create Task
    3. Give a task name(Should be unique)





    1. Click on Triggers tab
    In here you have to add two triggers. First one as a schedule and second one as a system start up one.

    Click on "New" button and add the following information in the New Trigger window.

    Trigger 1



    Trigger 2



    Finally you can see the created list of triggers.



    1. After that you need to specify the created .bat file's path location in the Action tab as mentioned in below.



    1. In the condition tab:



    Note : if you are using a lap top make sure to deselect the 2 Power options. Otherwise the task may not run until the power cable is connecting.

    1. In Settings tab do the following.



    1. Now click OK button. Now your windows task will be run on scheduled time.

Write windows .bat file to execute a PHP file

    1. Open a notepad and write the following command

    Path to your php.exe file -f "path to your php script where you want to execute "

    E.g.:
    C:\wamp\bin\php\php5.3.13\php.exe -f "C:\wamp\www\TestFramework\src\controllers\Email.php"

    1. Save the file with any with .bat extension.



    1. You can directly run this .bat file also. In windows 7 make sure to run it under Administration privileges. But it is not nice to run the batch file manually all the time. So we can use Windows task scheduler to do this. 

Tuesday, March 18, 2014

How to send a mail using PHPMailer

It is really very easy to use PHPMailer rather than use of PHP default mail() function.
  • Ease of use.
  • Much flexible.
  • Can have user authentication which php mail() doesn't have.

Before start, you need to download PHPMailer zip source files. You can download that freely fromthe internet (https://github.com/PHPMailer/PHPMailer).

Then you will require files  class.phpmailer.php and class.smtp.php from the downloaded source files.

In class.phpmailer.php modify required fields like;
username, password, etc.. 

In class.smtp.php modify required fields like;
port

Sample mail code :
IsSMTP();  // telling the class to use SMTP
$mail->Host     = "mail.xxx.com"; // SMTP server

$mail->From     = "chathuryad@xxxx.com";
$mail->AddAddress("chathuryad@xxxx.com");

$mail->Subject  = "First PHPMailer Message";
$mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";


if(!$mail->Send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
}
?>

If you try to send mail in a loop sometimes it will send the mail for everyone. So after sending the mail it would be a good practice to remove the address from the php mail list.

$mail->ClearAllRecipients( );