Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA SendMessageService

From Leeroopedia
Knowledge Sources
Domains Email, User_Registration
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete email service for sending verification codes via SMTP with random email server selection and automatic failover to a different server on error.

Description

The SendMessageService class sends HTML-formatted verification code emails using javax.mail. It randomly selects an SMTP server from the configured email list, generates a 6-digit code, sends the email, and caches the code in Redis. On `MessagingException`, it removes the failed email config from the list and retries with a different server.

Usage

Inject this component when implementing email verification flows. Call `sendEmail()` with the recipient email address.

Code Reference

Source Location

Signature

@Component
public class SendMessageService {

    public String emailForm = "";

    @Resource
    RedisUtil redisUtil;
    @Resource
    IEmailService emailService;

    public void sendEmail(String email);
    public Session createSession();
}

Import

import com.intelligent.bot.service.sys.SendMessageService;

I/O Contract

Inputs

Name Type Required Description
email String Yes Recipient email address

Outputs

Name Type Description
Redis cache String 6-digit verification code cached at "email:code:{email}"

Usage Examples

Send Verification Code

// Send 6-digit code to user's email
sendMessageService.sendEmail("user@example.com");

// Code is cached in Redis
String code = RedisUtil.getCacheObject("email:code:user@example.com");
// "123456"

Failover Behavior

// If SMTP fails for "server1@qq.com":
// 1. Remove "server1@qq.com" from email list in Redis
// 2. Retry with a different server from the list
// 3. If no servers left, throws "暂无可用的邮件服务"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment