Send email script works on Win, but not on Android - python-3.x

This script sends mail when is ran on Windows and Linux, but not on Andorid. What is the issue?
My app requirements in p-4-a are python3, kivy, openssl. Permission is INTERNET. App crashes when I run method below.
def send_report(self):
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('sender_email', 'sender_pass')
server.sendmail('sender_email', 'receiver_email', 'Some msg')
server.close()

Related

Django - webbrowser.open doesn`t work in production mode

I am developing an app that should send msg by WhatsApp. Running from Django Development Server works fine, but from Xampp it doesn't, I even tried opening whatsapp from the url directly in the project and it doesn't work either. The problem is open function from webbrowser module.
Python 3.10.6
Django 3.2.0
def send_whatsapp(telefono, mensaje):
try:
webbrowser.open_new_tab(f"https://web.whatsapp.com/send?phone={telefono}&text={mensaje}")
print("Mensaje enviado")
except Exception:
print("Error")
Thanks!!

How to send emails via outlook using terminal sever

I have a python script which is used to send email through outlook, but the script has got my system's path,
now I have to run this script on centralised system using putty, as the code is now on git, how do I change the path for 'mail.Attachments' section.
Below is the script which runs fine on my local machine, but when i try to run it on putty it throws error, module win32com.client not found and doesn't even allow me to install pywin32
import win32com.client
outlook = win32com.client.Dispatch('outlook.application')
mail = outlook.createItem(0)
mail.To = 'xsupport#xsample.com '
mail.Subject = 'certificate CSR'
mail.Body = "Attached is the CSR for 'xxx.sample.com'.\
\nPlease request a duplicate certificate for the Cert Project.\
\n\nThanks,\nPraveen"
mail.Attachments.Add('C:/Users/praveen23/akamai_cert/sample.pem')
mail.Send()

django and telegram bot

from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext
import secrets
def start(update: Update, context: CallbackContext) -> None:
chat_id = update.effective_chat.id
context.bot.send_message(chat_id=chat_id,
text=f"Thank you for using our telegram bot! We will send you notifications here!")
def main():
updater = Updater('53049746:27b1xn8KRQdCdFERPVw7o')
updater.dispatcher.add_handler(CommandHandler('start', start))
# Start the Bot
updater.start_polling( )
# timeout=300
# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT
updater.idle()
main()
This is code for my telegram bot, I run it like python3 bot.py and it works:
The question is: I have django project, so I need to run this bot.py in the background what is the best way to do it? (Right now I start my django project as python3 manage.py start server, later will use docker for it)
UPDATE:
I need bot.py to response to commands like /start, /info, /help, etc`
And I need django app to make some urls like mywebsite.com/send_telegram_msg?user_id=123123123123 which will trigger my bot to send msg

Seeing terminal logs of Flask App after session on server ended but app is still running on background

The scenario is below:
I SSH to server Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-96-generic
x86_64) using putty with my credentials, from Windows
Go to the directory where I put my source code
start Flask app by running command python3 main.py logs are showing on terminal
however, after I left my computer for some time the session is disconnected/ended.
I know the app still running because another team still can test the app
when I re-login to the server and go to the same directory I don't want to kill/restart the already running app because it would interfere with others doing the test
How to see the running log so I would know what testers are doing and occasionally catch what's wrong
my main.py code:
if __name__ == "__main__":
ip = 'someip'
port = 9053
app.run(debug=True, host=os.getenv('IP', ip),
port=int(os.getenv('PORT', port)), threaded=True)
you can save your python log on file, so you can review it any time, this the example of using logging lib:
import logging
logger = logging.getLogger(<logging_name>)
fh = logging.FileHandler(<logging file>)
logger.addHandler(fh)

Send an email from a Python3 script with localhost?

I need to send mails from my Python3 script. Now it does, but my gmail password is visible and I cannot trust in any admin of this machine, so the solution I see is to mount a local mail server. To do some tests, I was trying to execute a script (this one: SMTP sink server). While this one is running, I execute my old script with some changes:
import smtplib
# server = smtplib.SMTP('smtp.gmail.com:587')
server = smtplib.SMTP('localhost:25')
# smtp.ehlo()
# server.starttls()
# smtp.ehlo()
# server.login('my_account#gmail.com', 'my_password')
server.login(None, None)
server.sendmail('Me <my_account#gmail.com'>, ['to_user#gmail.com'], 'Hi!'.as_string())
server.quit()
I understand the script at the link will create a file in the folder where it is with the mail content, but nothing happens, because I get this error message:
SMTP AUTH extension not supported by server.
I googled and I think this could be sorted out if I uncomment the line server.starttls(), but it gives another error, which is supposed to be solved with the lines smtp.ehlo(), but not in my case.
Any suggestions?
OK, I managed to send the email, what I only had to do was removing this line:
server.login(None, None)

Resources