Hello, I was making a bug report function using redmail library.
This is the library I was using-
Also I wanted to use st.file_uploader() and include the photos in my email.
But I cannot decode the uploaded file into usable bytes(?).
Can you try my code and see what is wrong in here?
import streamlit as st
from redmail import gmail
import base64
if 'send_email' not in st.session_state:
st.session_state.send_email=False
if 'username' not in st.session_state:
st.session_state.username='Johnny'
st.subheader('Bug Report')
st.write("""
**Plz report any bugs bro**
**I wanna fix it bro**
""")
# Taking inputs
error_subject = st.text_input('Title')
error_body = st.text_area('Context')
error_image=st.file_uploader('Photos')
col1,col2=st.columns([8,2])
with col2:
if st.button("Send Email",use_container_width=True):
st.session_state.send_email=True
if st.session_state.send_email==True:
try:
base64_str = base64.b64encode(error_image.read())
imgdata = base64.b64decode(base64_str)
subtype_name=error_image.name[error_image.name.find('.')+1:]
gmail.username=st.secrets.admin_email
gmail.password=st.secrets.admin_pw
gmail.send(
subject=f'{error_subject}',
sender=f'{st.secrets.admin_email}',
receivers=[f'{st.secrets.bug_report_email}'],
html=f'''
<h5>user : {st.session_state.username}</h5>
<p>{error_body}</p>
{{myimage}}
''',
body_images={
'myimage':f'{imgdata}',
'subtype':f'{subtype_name}'
}
)
st.success('Email sent successfully! 🚀')
del st.session_state.send_email
except Exception as e:
st.error(f"Failed to send email: {e}")
else:
pass