Member Avatar for sravan953

Well, there are two problems.

1) in line 98, user should be self.user which will solve the error message. in line 88 user, passw should be self.user, self.passw

2) After fixing those two lines, try printing self.user and self.passw in the login function. When I did that it said that self.user is 'Login ID' and self.passw is 'Password' even after changing the user and password. The problem lies in where you GetValue(), you have it in __init__ where it will get the starting values when it should be in the functions that use it so user input is read.

Here's the code that seems to be working, with the changes from above. I've also added style=wx.TE_PASSWORD in line 46 to mask the password.

import smtplib
import time
import os
import wx

window=wx.App()

s=smtplib.SMTP("smtp.gmail.com",587)
s.starttls()

class pymailer(wx.Frame):
    
    def __init__(self):
        wx.Frame.__init__(self,None,-1,"Py-mailer",size=(500,700))

        self.info={}
        self.user=""
        self.passw=""
        self.to=""
        self.subject=""
        self.message=""

        self.panel=wx.Panel(self,-1)
        
        menubar=wx.MenuBar()

        filem=wx.Menu()
        filem.Append(201,"Quit")
        self.Bind(wx.EVT_MENU,self.Quit,id=201)

        viewm=wx.Menu()
        viewm.Append(202,"About")
        self.Bind(wx.EVT_MENU,self.About,id=202)

        menubar.Append(filem,"File")
        menubar.Append(viewm,"Help")

        self.SetMenuBar(menubar)

        wx.StaticText(self.panel,-1,"Welcome to Py-mailer.\nLogin with your Gmail credentials and you can send a text-only email to anyone quickly and easily.",pos=(10,10))
        wx.StaticText(self.panel,-1,"Please enter your Gmail login ID: ",pos=(10,100))
        wx.StaticText(self.panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130))

        self.username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100))
        
        self.password=wx.TextCtrl(self.panel,102,"Password",pos=(220,130), style=wx.TE_PASSWORD)

        login=wx.Button(self.panel,103,label="Login",pos=(10,170))
        self.Bind(wx.EVT_BUTTON,self.Login,id=103)
        
        wx.StaticText(self.panel,-1,"To:",pos=(10,250))
        wx.StaticText(self.panel,-1,"Subject:",pos=(10,280))
        wx.StaticText(self.panel,-1,"Message:",pos=(10,310))

        self.to_info=wx.TextCtrl(self.panel,104,pos=(80,250),size=(240,20))
        
        self.sbj_info=wx.TextCtrl(self.panel,105,pos=(80,280),size=(240,20))
     
        self.msg_info=wx.TextCtrl(self.panel,106,pos=(80,310),size=(240,150))

        send=wx.Button(self.panel,107,"Send",pos=(245,470))
        self.Bind(wx.EVT_BUTTON,self.Send,id=107)

        self.Centre()
        self.Show()

    def Quit(self,event):
        self.Close()
    
    def About(self,event):
        about=wx.AboutDialogInfo()
        
        about.SetName("Py-Mailer")
        about.SetCopyright("(c) 2009 Sravan")
        about.SetWebSite("http://www.uberpix.wordpress.com")
        about.AddDeveloper("Sravan")
        about.AddDeveloper("Dan")

        wx.AboutBox(about)

    def Login(self,event):
        self.user=self.username.GetValue()
        self.passw=self.password.GetValue()
        try:
            s.login(self.user,self.passw)
            wx.StaticText(self.panel,-1,"Logged in...",pos=(10,200))
        except:
            wx.StaticText(self.panel,-1,"Failed",pos=(10,200))

    def Send(self,event):
        self.info["To"]=self.to_info.GetValue()
        self.info["Subject"]=self.sbj_info.GetValue()
        self.info["Message"]=self.msg_info.GetValue()
        to=self.info["To"]
        subject=self.info["Subject"]
        message=self.info["Message"]
        msg="To: "+to+"\nSubject: "+subject+"\n"+message
        s.sendmail(self.user,to,msg)
        s.quit()

pymailer()
window.MainLoop()

Oh ofcourse! Just a few days ago, I was working on a program, where I used GetValue() IN the function...don't know why it didn't strike to me! ;)

Anyways thanks...

Member Avatar for sravan953

Another problem, I logged in successfully and I wanted to send the email to myself, but it showed this error:

Traceback (most recent call last):
File "C:\Documents and Settings\sravan953\My Documents\Sravan\PYTHON\Py-mailer_GUI.py", line 92, in Send
self.s.sendmail(self.user,self.to,self.msg)
File "C:\Python26\lib\smtplib.py", line 709, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {u'': (555, '5.5.2 Syntax error. 21sm1238224pxi.7')}

Are you sure you filled in the To: field right? I've been able to send to myself and the only way I got a similar message was to not fill in the To: field.

Member Avatar for sravan953

Yes, I entered my own email ID (sravan953@gmail.com) and I tried, but it didn't work, is there anything wrong?

import smtplib
import time
import os
import wx

window=wx.App()

class pymailer(wx.Frame):
    
    def __init__(self):
        wx.Frame.__init__(self,None,-1,"Py-mailer",size=(500,700))

        self.info={}

        self.s=smtplib.SMTP("smtp.gmail.com",587)
        self.s.starttls()

        self.panel=wx.Panel(self,-1)
        
        menubar=wx.MenuBar()

        filem=wx.Menu()
        filem.Append(201,"Quit")
        self.Bind(wx.EVT_MENU,self.Quit,id=201)

        viewm=wx.Menu()
        viewm.Append(202,"About")
        self.Bind(wx.EVT_MENU,self.About,id=202)

        menubar.Append(filem,"File")
        menubar.Append(viewm,"Help")

        self.SetMenuBar(menubar)

        wx.StaticText(self.panel,-1,"Welcome to Py-mailer.\nLogin with your Gmail credentials and you can send a text-only email to anyone quickly and easily.",pos=(10,10))
        wx.StaticText(self.panel,-1,"Please enter your Gmail login ID: ",pos=(10,100))
        wx.StaticText(self.panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130))

        self.username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100))        
        self.password=wx.TextCtrl(self.panel,102,"Password",style=(wx.TE_PASSWORD),pos=(220,130))

        login=wx.Button(self.panel,103,label="Login",pos=(10,170))
        self.Bind(wx.EVT_BUTTON,self.Login,id=103)
        
        wx.StaticText(self.panel,-1,"To:",pos=(10,250))
        wx.StaticText(self.panel,-1,"Subject:",pos=(10,280))
        wx.StaticText(self.panel,-1,"Message:",pos=(10,310))

        to_info=wx.TextCtrl(self.panel,104,pos=(80,250),size=(240,20))
        self.info["To"]=to_info.GetValue()
        
        sbj_info=wx.TextCtrl(self.panel,105,pos=(80,280),size=(240,20))
        self.info["Subject"]=sbj_info.GetValue()
        
        msg_info=wx.TextCtrl(self.panel,106,pos=(80,310),size=(240,150))
        self.info["Message"]=msg_info.GetValue()

        send=wx.Button(self.panel,107,"Send",pos=(245,470))
        self.Bind(wx.EVT_BUTTON,self.Send,id=107)

        self.Centre()
        self.Show()

    def Quit(self,event):
        self.Close()
    
    def About(self,event):
        about=wx.AboutDialogInfo()
        
        about.SetName("Py-Mailer")
        about.SetCopyright("(c) 2009 Sravan")
        about.SetWebSite("http://www.uberpix.wordpress.com")
        about.AddDeveloper("Sravan")
        about.AddDeveloper("Dan")

        wx.AboutBox(about)

    def Login(self,event):
        self.user=self.username.GetValue()
        self.passw=self.password.GetValue()
        try:
            self.s.login(self.user,self.passw)
            wx.StaticText(self.panel,-1,"Logged in...",pos=(10,200))
        except:
            wx.StaticText(self.panel,-1,"Failed",pos=(10,200))

    def Send(self,event):
        self.to=self.info["To"]
        self.subject=self.info["Subject"]
        self.message=self.info["Message"]
        self.msg="To: "+self.to+"\nSubject: "+self.subject+"\n"+self.message
        self.s.sendmail(self.user,self.to,self.msg)
        self.s.quit()

pymailer()
window.MainLoop()
Member Avatar for sravan953

I scrutinized the error and found out it mentioned a 'syntax error'?

Put this in and try again.

s=smtplib.SMTP("smtp.gmail.com",587)
s.ehlo()
s.starttls()
s.ehlo()
Member Avatar for sravan953

Same thing, shows the error

The GetValues() for the fields to, subject and message are still in __init__ not in the Send function

commented: Great observer +0
Member Avatar for sravan953

OH! So stupid of me! I fixed that winmic! ;)

Member Avatar for sravan953

FINALLY! It works! Thanks a lot you guys! Couldn't have done it without you!

Member Avatar for sravan953

Although this is off-topic: I have Python 2.6.3, I installed py2exe 0.6.9, and when I try to compile the program it gives some error, I can't post the error since I can't copy text from the command prompt. I did mention something about wx.core and some dll file (MSVCP90.dll). It works fine for other non-wxpython programs, but it doesn't work with this! How do I solve this?

Although this is off-topic: I have Python 2.6.3, I installed py2exe 0.6.9, and when I try to compile the program it gives some error, I can't post the error since I can't copy text from the command prompt. I did mention something about wx.core and some dll file (MSVCP90.dll). It works fine for other non-wxpython programs, but it doesn't work with this! How do I solve this?

Do you you code setup.py by yourself?
If yes, Andrea Gavana have saved you alot of pain by making front end (GUI) for py2exe. It is called GUI2exe
Get It here:
http://code.google.com/p/gui2exe/
I use it with inno setup to make setups
It is fantastic work!

If you still get errors, then open new thread. Oh by the way, Using wing IDE (101 version is free) will help you copy and paste errors. Any other decent IDE should be able to do that (even IDLE :))

Member Avatar for sravan953

Thanks mate, will try it out soon!

Member Avatar for sravan953

Can you give me a detailed HOW-TO on how to go about converting my GUI Python file to an exe...? I will use Inno Setup later to make a setup for it, but first I want to make an exe..

Member Avatar for sravan953

Even using GUI2exe, it gives the same error:

error: MSVCP90.dll: No such file or directory

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.