Created
April 11, 2015 04:22
-
-
Save GreeeenApple/f58dab01069bfa3d36de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import smtplib | |
import email | |
import wx | |
HOST = "hogehoge.jp" | |
def click_post(event): | |
from_address = text1.GetValue() | |
to_address = text2.GetValue() | |
title = text3.GetValue() | |
body = text4.GetValue() | |
charset = "ISO-2022-JP" | |
data = email.MIMEText.MIMEText(body.encode(charset), "plain", charset) | |
data["Subject"] = email.Header.Header(title, charset) | |
data["From"] = from_address | |
data["To"] = to_address | |
smtp = smtplib.SMTP(HOST) | |
try: | |
smtp.sendmail(from_address, to_address, data.as_string()) | |
except: | |
frame.SetStatusText("------送信に失敗しました-----") | |
else: | |
frame.SetStatusText("------送信完了-----") | |
finally: | |
smtp.quit() | |
print(from_address, to_address, title, body) | |
if __name__ == "__main__": | |
app = wx.App() | |
frame = wx.Frame(None, wx.ID_ANY, "MAIL SENDER", size=(600,500)) | |
frame.CreateStatusBar() | |
root_panel = wx.Panel(frame, wx.ID_ANY) | |
s_text1 = wx.StaticText(root_panel,wx.ID_ANY,"FROM\t:") | |
text1 = wx.TextCtrl(root_panel, wx.ID_ANY, "") | |
s_text1.SetBackgroundColour("#0000FF") | |
s_text2 = wx.StaticText(root_panel,wx.ID_ANY,"TO\t\t:") | |
text2 = wx.TextCtrl(root_panel, wx.ID_ANY, "") | |
s_text3 = wx.StaticText(root_panel,wx.ID_ANY,"TITLE\t:") | |
text3 = wx.TextCtrl(root_panel, wx.ID_ANY, "") | |
s_text4 = wx.StaticText(root_panel,wx.ID_ANY,"BODY\t:") | |
text4 = wx.TextCtrl(root_panel, wx.ID_ANY, "",style=wx.TE_MULTILINE, size=(100,100)) | |
s_text5 = wx.StaticText(root_panel,wx.ID_ANY,"") | |
button1 = wx.Button(root_panel,wx.ID_ANY,"送信", size=(100,100)) | |
button1.Bind(wx.EVT_BUTTON, click_post) | |
layout1 = wx.FlexGridSizer(6,2) | |
layout1.Add(s_text1, flag=wx.SHAPED|wx.ALIGN_LEFT) | |
layout1.Add(text1, flag=wx.GROW) | |
layout1.Add(s_text2, flag=wx.SHAPED|wx.ALIGN_LEFT) | |
layout1.Add(text2, flag=wx.GROW) | |
layout1.Add(s_text3, flag=wx.SHAPED|wx.ALIGN_LEFT) | |
layout1.Add(text3, flag=wx.GROW) | |
layout1.Add(s_text4, flag=wx.SHAPED|wx.ALIGN_LEFT) | |
layout1.Add(text4, flag=wx.GROW) | |
layout1.Add(s_text5, flag=wx.SHAPED|wx.ALIGN_LEFT) | |
layout1.Add(button1, flag=wx.GROW) | |
layout1.AddGrowableRow(3) | |
layout1.AddGrowableCol(1) | |
root_panel.SetSizer(layout1) | |
frame.Show() | |
app.MainLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment