Program to automatically send email works perfectly according to IDLE, but the email is never received












0















I've been making a program in python to work towards sending emails automatically. It should be quite simple.



I've tried multiple different methods and after an hour of experimenting with new and unfarmiliar modules I have finally come to the code that I have now.



import smtplib, ssl
port = 587
server_name = 'smtp.gmail.com'
email = 'not_telling_you@my_email.com'
recipient = 'not_telling_you1@my_email.com'
message = 'Hello world'
context = ssl.create_default_context()
print('Having trouble? Go to "accounts.google.com > settings > less secure app access > turn on access > on" when using a gmail account. It is not recommended to do this with your normal account.')

import tkinter as tk

class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()

def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Log in"
self.hi_there["command"] = self.login
self.hi_there.pack(side="top")

self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")

def login(self):
server = smtplib.SMTP(server_name, port)
print('Connecting to server...')
server.ehlo()
server.starttls()
server.ehlo()
print('Successfully connected to', server_name, 'through port', port)
print('Logging in...')
server.login(email,'****************')
print('Successfully logged into', email)
server.sendmail(email, recipient, message)
print('Successfully sent', message, 'from', email, 'to', recipient)

root = tk.Tk()
app = Application(master=root)
app.mainloop()


It should simply send the email automatically when the user clicks login (I haven't bothered to change what it says, I'm building off of a bit of an older program). It gets to the sent box of the sender email,but the recipient never receives the email.










share|improve this question























  • You should implement logging into your code. This will help examine the sequence of execution and any problems whatsoever. The recipient may check the Junk/Spam folder in their mailbox or other email settings to allow emails from this particular email address/domain.

    – amanb
    Jan 3 at 19:54






  • 2





    Your message is also not a valid mail message which should consist of a header with From, To, Subject ... and a body. It is not unlikely that such bad mails get silently discarded - specifically outlook/hotmail/live.com is known for accepting mail which looks bad or looks like spam but then discarding it. Gmail instead usually reject mails if they don't like it but even if accepted they might automatically end up in the spam folder of the recipient.

    – Steffen Ullrich
    Jan 3 at 20:23


















0















I've been making a program in python to work towards sending emails automatically. It should be quite simple.



I've tried multiple different methods and after an hour of experimenting with new and unfarmiliar modules I have finally come to the code that I have now.



import smtplib, ssl
port = 587
server_name = 'smtp.gmail.com'
email = 'not_telling_you@my_email.com'
recipient = 'not_telling_you1@my_email.com'
message = 'Hello world'
context = ssl.create_default_context()
print('Having trouble? Go to "accounts.google.com > settings > less secure app access > turn on access > on" when using a gmail account. It is not recommended to do this with your normal account.')

import tkinter as tk

class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()

def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Log in"
self.hi_there["command"] = self.login
self.hi_there.pack(side="top")

self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")

def login(self):
server = smtplib.SMTP(server_name, port)
print('Connecting to server...')
server.ehlo()
server.starttls()
server.ehlo()
print('Successfully connected to', server_name, 'through port', port)
print('Logging in...')
server.login(email,'****************')
print('Successfully logged into', email)
server.sendmail(email, recipient, message)
print('Successfully sent', message, 'from', email, 'to', recipient)

root = tk.Tk()
app = Application(master=root)
app.mainloop()


It should simply send the email automatically when the user clicks login (I haven't bothered to change what it says, I'm building off of a bit of an older program). It gets to the sent box of the sender email,but the recipient never receives the email.










share|improve this question























  • You should implement logging into your code. This will help examine the sequence of execution and any problems whatsoever. The recipient may check the Junk/Spam folder in their mailbox or other email settings to allow emails from this particular email address/domain.

    – amanb
    Jan 3 at 19:54






  • 2





    Your message is also not a valid mail message which should consist of a header with From, To, Subject ... and a body. It is not unlikely that such bad mails get silently discarded - specifically outlook/hotmail/live.com is known for accepting mail which looks bad or looks like spam but then discarding it. Gmail instead usually reject mails if they don't like it but even if accepted they might automatically end up in the spam folder of the recipient.

    – Steffen Ullrich
    Jan 3 at 20:23
















0












0








0


1






I've been making a program in python to work towards sending emails automatically. It should be quite simple.



I've tried multiple different methods and after an hour of experimenting with new and unfarmiliar modules I have finally come to the code that I have now.



import smtplib, ssl
port = 587
server_name = 'smtp.gmail.com'
email = 'not_telling_you@my_email.com'
recipient = 'not_telling_you1@my_email.com'
message = 'Hello world'
context = ssl.create_default_context()
print('Having trouble? Go to "accounts.google.com > settings > less secure app access > turn on access > on" when using a gmail account. It is not recommended to do this with your normal account.')

import tkinter as tk

class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()

def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Log in"
self.hi_there["command"] = self.login
self.hi_there.pack(side="top")

self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")

def login(self):
server = smtplib.SMTP(server_name, port)
print('Connecting to server...')
server.ehlo()
server.starttls()
server.ehlo()
print('Successfully connected to', server_name, 'through port', port)
print('Logging in...')
server.login(email,'****************')
print('Successfully logged into', email)
server.sendmail(email, recipient, message)
print('Successfully sent', message, 'from', email, 'to', recipient)

root = tk.Tk()
app = Application(master=root)
app.mainloop()


It should simply send the email automatically when the user clicks login (I haven't bothered to change what it says, I'm building off of a bit of an older program). It gets to the sent box of the sender email,but the recipient never receives the email.










share|improve this question














I've been making a program in python to work towards sending emails automatically. It should be quite simple.



I've tried multiple different methods and after an hour of experimenting with new and unfarmiliar modules I have finally come to the code that I have now.



import smtplib, ssl
port = 587
server_name = 'smtp.gmail.com'
email = 'not_telling_you@my_email.com'
recipient = 'not_telling_you1@my_email.com'
message = 'Hello world'
context = ssl.create_default_context()
print('Having trouble? Go to "accounts.google.com > settings > less secure app access > turn on access > on" when using a gmail account. It is not recommended to do this with your normal account.')

import tkinter as tk

class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()

def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Log in"
self.hi_there["command"] = self.login
self.hi_there.pack(side="top")

self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")

def login(self):
server = smtplib.SMTP(server_name, port)
print('Connecting to server...')
server.ehlo()
server.starttls()
server.ehlo()
print('Successfully connected to', server_name, 'through port', port)
print('Logging in...')
server.login(email,'****************')
print('Successfully logged into', email)
server.sendmail(email, recipient, message)
print('Successfully sent', message, 'from', email, 'to', recipient)

root = tk.Tk()
app = Application(master=root)
app.mainloop()


It should simply send the email automatically when the user clicks login (I haven't bothered to change what it says, I'm building off of a bit of an older program). It gets to the sent box of the sender email,but the recipient never receives the email.







python ssl smtplib






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 19:49









Josh BruntonJosh Brunton

153




153













  • You should implement logging into your code. This will help examine the sequence of execution and any problems whatsoever. The recipient may check the Junk/Spam folder in their mailbox or other email settings to allow emails from this particular email address/domain.

    – amanb
    Jan 3 at 19:54






  • 2





    Your message is also not a valid mail message which should consist of a header with From, To, Subject ... and a body. It is not unlikely that such bad mails get silently discarded - specifically outlook/hotmail/live.com is known for accepting mail which looks bad or looks like spam but then discarding it. Gmail instead usually reject mails if they don't like it but even if accepted they might automatically end up in the spam folder of the recipient.

    – Steffen Ullrich
    Jan 3 at 20:23





















  • You should implement logging into your code. This will help examine the sequence of execution and any problems whatsoever. The recipient may check the Junk/Spam folder in their mailbox or other email settings to allow emails from this particular email address/domain.

    – amanb
    Jan 3 at 19:54






  • 2





    Your message is also not a valid mail message which should consist of a header with From, To, Subject ... and a body. It is not unlikely that such bad mails get silently discarded - specifically outlook/hotmail/live.com is known for accepting mail which looks bad or looks like spam but then discarding it. Gmail instead usually reject mails if they don't like it but even if accepted they might automatically end up in the spam folder of the recipient.

    – Steffen Ullrich
    Jan 3 at 20:23



















You should implement logging into your code. This will help examine the sequence of execution and any problems whatsoever. The recipient may check the Junk/Spam folder in their mailbox or other email settings to allow emails from this particular email address/domain.

– amanb
Jan 3 at 19:54





You should implement logging into your code. This will help examine the sequence of execution and any problems whatsoever. The recipient may check the Junk/Spam folder in their mailbox or other email settings to allow emails from this particular email address/domain.

– amanb
Jan 3 at 19:54




2




2





Your message is also not a valid mail message which should consist of a header with From, To, Subject ... and a body. It is not unlikely that such bad mails get silently discarded - specifically outlook/hotmail/live.com is known for accepting mail which looks bad or looks like spam but then discarding it. Gmail instead usually reject mails if they don't like it but even if accepted they might automatically end up in the spam folder of the recipient.

– Steffen Ullrich
Jan 3 at 20:23







Your message is also not a valid mail message which should consist of a header with From, To, Subject ... and a body. It is not unlikely that such bad mails get silently discarded - specifically outlook/hotmail/live.com is known for accepting mail which looks bad or looks like spam but then discarding it. Gmail instead usually reject mails if they don't like it but even if accepted they might automatically end up in the spam folder of the recipient.

– Steffen Ullrich
Jan 3 at 20:23














0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54028881%2fprogram-to-automatically-send-email-works-perfectly-according-to-idle-but-the-e%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54028881%2fprogram-to-automatically-send-email-works-perfectly-according-to-idle-but-the-e%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas