Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Saturday, April 13, 2013

Best way to do calculations on linux console

I always used shell to do all calculation stuff but using it can be sometimes can be a little tricky.

Then I came across python doing calculations on python is very very simple.

Example : 

console[1] python
Python 2.4.3 (#1, Dec 22 2011, 12:12:01)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> t1 = 32*60 +8.1
>>> t2 = 33 *60 +35.1
>>> (t2-t1)/t2
0.043174036027988687
>>>



So you just have to type python and start doing calculations.

Wednesday, April 3, 2013

Sending automated mails to Gmail/ Email bomb

While surfing net I found this amazing code which can be used to automated mails to gmail users.

Its written in python so you need to have python installed on your system to get it running.

def send_email():
    import smtplib

    gmail_user = "gmail_user@gmail.com"
    gmail_pwd = "password"
    FROM = 'gmail_uswr@gmail.com'
    TO = ['gmail_target@gmail.com'] #must be a list
    SUBJECT = "Testing sending using gmail"
    TEXT = "Testing sending mail using gmail servers"

    # Prepare actual message
    message = """\From: %s\nTo: %s\nSubject: %s\n\n%s""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
    try:
        #server = smtplib.SMTP(SERVER)
        server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
        print "print 1"
        server.ehlo()
        print "print 2"
        server.starttls()
        print "print 3"
        server.ehlo()
        server.login(gmail_user, gmail_pwd)
        print "print 4"
        server.sendmail(FROM, TO, message)
        print "print 5"
        #server.quit()
        server.close()
        print 'successfully sent the mail'
    except:
        print "failed to send mail"

send_email()

In order to send 100's of mail to an user just put send_mail() inside a loop your email bomb is ready. :P

PS: This code is not written by me but I found in while surfing net.

PPS: Do not use this on my email-id :).