What I’m trying to do:
I am trying to send email from my app, but is not working., I dont get any errors, but never get the emails send. Even tought I tried the Test setting and commes back green
What I’ve tried and what’s not working:
Tried without images, minimun text, different emails.
Code Sample:
@anvil.server.callable
def send_images_to_process(doctor_email, images):
try:
# Load doctor information
doctor_info = load_doctor_by_email(doctor_email)
if not doctor_info:
return False
# Create a zip file with the images
zip_buffer = BytesIO()
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
for image in images:
# Write each image to the zip file
with anvil.media.TempFile(image) as temp_file:
zip_file.write(temp_file, arcname=image.name)
# Reset buffer position
zip_buffer.seek(0)
# Create a media object for the zip file
zip_media = anvil.BlobMedia("application/zip", zip_buffer.read(), name="images.zip")
# Send email with doctor information and the zip file
email_body = f"""
Dear Dr. {doctor_info['first_name']} {doctor_info['last_name']},
Please find the images attached for your review.
Specialty: {doctor_info['specialty']}
Phone Number: {doctor_info['phone_number']}
"""
anvil.email.send(
from_name = "My App Support",
to='****@sangre-viva.com', # Use doctor_info["email"] for dynamic email
subject="Images for Review",
text=email_body,
attachments=[zip_media]
)
print("Email sent successfully.")
return True
except Exception as e:
# Log the exception for debugging purposes
print(f"Error sending email: {e}")
return False
–Custom SMTP Settings–
Host: mail.sangre-viva.com
Port: 465
Encryption: SSL
Username: ****@sangre-viva.com
Password: *****
Test settings: Connection succeeded
Thanks!