Implementation:A616567126 GPT WEB JAVA SendMessageService
| 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
- Repository: A616567126_GPT_WEB_JAVA
- File: src/main/java/com/intelligent/bot/service/sys/SendMessageService.java
- Lines: 1-97
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 |
|---|---|---|---|
| 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 "暂无可用的邮件服务"