Hi, I'm experiencing a **similar SMTP error: `535 5.7.8 Error: authentication failed`** when trying to send emails through **Titan Mail** (Hostinger), but I'm using **Python** instead of PHP.
I'm sure that the username and password are correct — I even reset them to double-check. I've tried using both ports `587` (TLS) and `465` (SSL), but I always get the same authentication error.
Below is my implementation in Python:
```python
from abc import ABC, abstractmethod
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
class TitanEmailInput:
def __init__(self, to: list[str], cc: list[str] = None, bcc: list[str] = None, subject: str = "", body: str = ""):
self.to = to
assert isinstance(self.to, list) and all(isinstance(email, str) for email in self.to), "To must be a list of strings"
assert len(self.to) > 0, "At least one recipient email is required"
self.cc = cc if cc is not None else []
if self.cc:
assert isinstance(self.cc, list) and all(isinstance(email, str) for email in self.cc), "CC must be a list of strings"
assert len(self.cc) > 0, "CC must be a list of strings"
self.bcc = bcc if bcc is not None else []
if self.bcc:
assert isinstance(self.bcc, list) and all(isinstance(email, str) for email in self.bcc), "BCC must be a list of strings"
assert len(self.bcc) > 0, "BCC must be a list of strings"
self.subject = subject
assert isinstance(self.subject, str), "Subject must be a string"
assert len(self.subject) > 0, "Subject cannot be empty"
self.body = body
assert isinstance(self.body, str), "Body must be a string"
class ITitanEmailSender(ABC):
@abstractmethod
def send_email(self, email_input: TitanEmailInput) -> None:
pass
class TitanEmailSender(ITitanEmailSender):
def __init__(self):
self.email = os.getenv("TITAN_EMAIL")
assert self.email, "TITAN_EMAIL environment variable is not set"
self.password = os.getenv("TITAN_EMAIL_PASSWORD")
assert self.password, "TITAN_EMAIL_PASSWORD environment variable is not set"
def send_email(self, email_input: TitanEmailInput) -> None:
msg = MIMEMultipart()
msg["From"] = self.email
msg["To"] = ", ".join(email_input.to)
if email_input.cc:
msg["Cc"] = ", ".join(email_input.cc)
if email_input.bcc:
bcc_list = email_input.bcc
else:
bcc_list = []
msg["Subject"] = email_input.subject
msg.attach(MIMEText(email_input.body, "plain"))
recipients = email_input.to + email_input.cc + bcc_list
try:
with smtplib.SMTP_SSL("smtp.titan.email", 465) as server:
server.login(self.email, self.password)
server.sendmail(self.email, recipients, msg.as_string())
except Exception as e:
raise RuntimeError(f"Failed to send email: {e}")
Any ideas on what might be causing this, or if there's something specific to Titan Mail I should be aware of when using SMTP libraries?
Thanks in advance!