20100714

dir(skype2mail.elements) (prg03)

#language :: python (2.6.4)
#date :: 14072010
#author :: gerganov

#============================================
#List processes and check if process is running...
import win32com.client

WMI = GetObject('winmgmts:')
processes = WMI.InstancesOf('Win32_Process')
procnames = [process.Properties_('Name').Value for process in processes]

for name in procnames:
         #check for name here
#============================================


#============================================
#Send e-mail with attachment(s) from Outlook Client...
import win32com.client

def sendmail(txt, sbj, rec, prf="Outlook"):
         s = win32com.client.Dispatch("Mapi.Session")
         o = win32com.client.Dispatch("Outlook.Application")

         s.Logon(prf)
         emsg = o.CreateItem(0)
         emsg.To = rec #can be added as argument, if multiple

         emsg.Subject = sbj
         emsg.Body = txt

         attachment1 = "..." #can be added as argument, if mulptiple
         emsg.Attachments.Add(attachment1)

         emsg.Send()

         s.Logoff()
         return
#============================================


#============================================
#Use Skype4Py and Python for Skype manipulation (SkypeAPI)...
import Skype4Py #http://sourceforge.net/projects/skype4py/

skype = Skype4Py.Skype()
skype.Attach() #Skype spawns a dialog - press Allow

#dir(skype) for available Functions and Variables
#documentation - http://skype4py.sourceforge.net/doc/html/
#============================================


#============================================
#Sleep with countdown...
def vsleep(act,sec):
         while(sec!=0):
                 print act + "(" + str(sec) + ") \r",
                 time.sleep(1.0)
                 sec -= 1
         print " "
         return
#============================================


#============================================
#Send e-mail from GMail with Python using Google as SMTP...
import os
import smtplib
import mimetypes
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEAudio import MIMEAudio
from email.MIMEImage import MIMEImage
from email.Encoders import encode_base64

def googlesend(sbj, txt, *atts):
         gmuser = 'x@gmail.com'
         gmpass = 'xpass'
         gmrecp = 'x@xdomain.xxx'

         msg = MIMEMultipart()
         msg['From'] = gmuser
         msg['To'] = recp
         msg['Subject'] = sbj
         msg.attach(MIMEText(txt))

         for att in atts:
                 msg.attach(getattachment(att))

         mailsvr = smtplib.SMTP('smtp.gmail.com', 587)
         mailsvr.ehlo()
         mailsvr.starttls()
         mailsvr.ehlo()
         mailsvr.login(gmuser, gmpass)
         mailsvr.sendmail(gmuser, recp, msg.as_string())
         mailsvr.close()
         return

def getatts(att):
         contentType, encoding = mimetypes.guess_type(att)

         if contentType is None or encoding is not None:
                 contentType = 'application/octet-stream'

         mainType, subType = contentType.split('/', 1)
         file = open(att, 'rb')

         if mainType == 'text':
                 attachment = MIMEText(file.read())
         elif mainType == 'message':
         attachment = email.message_from_file(file)
         elif mainType == 'image':
         attachment = MIMEImage(file.read(),_subType=subType)
         elif mainType == 'audio':
                 attachment = MIMEAudio(file.read(),_subType=subType)
         else:
                 attrdy = MIMEBase(mainType, subType)
         attrdy.set_payload(file.read())
         encode_base64(attrdy)

         file.close()

         attrdy.add_header('Content-Disposition', 'attachment', filename=os.path.basename(att))
         return attrdy
#============================================

#searchterms :: python and win32com, send outlook e-mail with python, send mail with python, google send mail with python, python skype, skype4py, python and skype4py, documentation skype4py, python list processes, find process python