#How to reduce request processing time for mail sender

1 messages · Page 1 of 1 (latest)

hidden garnet
#

Using java mail sender to send mails like otp for email verification, password reset and welcome message (new registrations). But it is taking too much time sometimes even >10 sec which i dont is very optimal as my average query takes < 2-3 sec.

How do i reduce this time

devout bloomBOT
#

<@&1004656351647117403> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
Using java mail sender to send mails like otp for email verification, password reset and welcome message (new registrations). But it is taking too much time sometimes even >10 sec which i dont is very optimal as my average query takes < 2-3 sec. How do i

To reduce the request processing time for sending emails with JavaMailSender, focus on optimizing asynchronous behavior and resource management:

  • Send emails asynchronously: Avoid blocking the main request thread. Use Spring’s @Async annotation or schedule email sending via a separate thread/executor service. This prevents the user from waiting while the mail is sent.
  • Connection reuse: Set up a JavaMailSender with connection pooling or reuse by configuring the mail session properties like mail.smtp.connectiontimeout, mail.smtp.timeout, and mail.smtp.writetimeout, or use libraries that support pooling.
  • Use SMTP server efficiently: Confirm your SMTP server performance isn't the bottleneck. Sometimes third-party SMTP providers can be slow; choosing one with low latency or third-party transactional email services (like SendGrid, Amazon SES) improves speed.
  • Optimize mail content: Keep email content minimal or use templates to reduce processing time.
  • Avoid heavy attachments: Large attachments delay sending.

Usually, the significant gain comes by making email sending asynchronous, so the API returns immediately while email processing happens in the background.


Useful links:

thorn dust
#

its probably the foreign mail server finding u sus and throttling it

#

mails send by some odd domain without a proper ssl cert etc arent thrusted

tired stump
#

As zabu said, it'll be the mail server itself and not java mail sender - that's typically pretty quick

weak swift
#

mail servers are slow to discourage spam

hidden garnet
weak swift
#

there isn't one

#

accept a 10 minute delay

hidden garnet
#

wtf

weak swift
#

oh 10 sec

#

thats more reasonable

#

but yeah just accept it

#

it might be best to send emails asynchronously

hidden garnet
#

i dont think other app take 10 sec to send a mail, or do they

weak swift
#

it depends on what domain they are sending from

#

and you wouldn't notice 10 sec

hidden garnet
weak swift
#

yeah - so insert a row into the db that a background task will pick up and send the email

hidden garnet
#

hm k

#

seems like i have to learn a new concept for that

weak swift
#

that has some other pros

#

like you can retry

#

or know which ones failed to send (if you track)

hidden garnet
#

hm

weak swift
#

we used to use sendgrid at my last company

#

it made a lot of this easier

#

but obv. costs money

hidden garnet
#

k not going to implement it right now, but will work on that in version 2

#

peepo_heart thanks for the info