
Вот что я пробовал. Электронное письмо отправляется хорошо, но в уведомлении нет кнопки «Копировать».
// HTML Template
private static final String OTP_EMAIL_TEMPLATE_HTML =
""
+ ""
+ ""
+ " body { font-family: Arial, sans-serif; line-height: 1.6; color: #374151; }"
+ " .container { max-width: 600px; margin: 20px auto; padding: 30px; border: 1px solid #d1d5db; border-radius: 12px; background-color: #ffffff; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); }"
+ " .header { font-size: 24px; font-weight: bold; color: #1f2937; margin-bottom: 25px; border-bottom: 1px solid #e5e7eb; padding-bottom: 15px; }"
+ " .otp-box { text-align: center; margin: 30px 0; }"
+ " .otp-code { "
+ " font-size: 40px; "
+ " font-weight: 900; "
+ " color: #059669; /* Bright Green */ "
+ " letter-spacing: 5px; "
+ " display: inline-block; "
+ " padding: 18px 30px; "
+ " border: 3px dashed #a7f3d0; "
+ " border-radius: 10px; "
+ " background-color: #f0fdf4; "
+ " white-space: nowrap; "
+ " }"
+ " .warning { color: #b91c1c; font-weight: bold; }"
+ " .detail { font-size: 14px; color: #6b7280; margin-top: 15px; border-top: 1px dashed #e5e7eb; padding-top: 15px; }"
+ ""
+ ""
+ ""
+ ""
+ " One-Time Passcode for %s" // %1$s: sysName
+ "
Dear %s,
" // %2$s: firstName
+ "
You recently requested a login to your %s account. Please use the following **Verification Code** to proceed:
" // %3$s: sysName
+ " "
+ " %s" // %4$s: code (The actual digits)
+ " "
+ "
This code expires in 5 minutes and should NEVER be shared with anyone.
"
+ " "
+ "
Login Attempt Details:
"
+ "
%s
" // %5$s: formattedUserAgent
+ "
If this was NOT you, please contact security immediately at: [url=mailto:%s]%s[/url]
" // %6$s, %7$s: securityEmail
+ " "
+ ""
+ ""
+ "";
//Plain Text Template
private static final String PLAIN_TEXT_TEMPLATE =
"Dear %s,\n\n" + // %1$s: firstName
"You recently requested a login to your %s account. Please use the following One-Time Password (OTP) to proceed:\n\n" + // %2$s: sysName
"********************\n" +
" VERIFICATION CODE: %s \n" + // %3$s: code
"********************\n\n" +
"This code expires in 5 minutes and should NEVER be shared with anyone.\n\n" +
"Login Attempt Details:\n%s\n\n" + // %4$s: formattedUserAgent
"If this was NOT you, please contact security immediately at %s\n\n" + // %5$s: securityEmail
"Thank you,\n" +
"The [Your Service Name] Team";
public synchronized int sendSecurityCode(
String dsName,
HttpServletRequest request,
SecretClient secretClient) {
// 1. Generate Code and Get System Properties
int code = generate6DigitNum();
String sysName = Monitor.getPropertyValue("SYSTEM_NAME");
String securityEmail = Monitor.getPropertyValue("SECURITY_EMAIL");
// 2. Update Security Code in Database
int result = updateSecCode(dsName, code);
// 3. Send Email only if DB update was successful (result == 1)
if (result == 1) {
UserAgentFormatter ua = new UserAgentFormatter();
String formattedUserAgent = ua.formatUserAgent(request);
String codeString = String.valueOf(code);
// 4. Generate the HTML Content
String htmlMessage = String.format(
OTP_EMAIL_TEMPLATE_HTML,
sysName, // %1$s
firstName, // %2$s
sysName, // %3$s
codeString, // %4$s: The actual 6-digit code
formattedUserAgent, // %5$s
securityEmail, // %6$s
securityEmail // %7$s
);
// 5. Generate the Plain Text Content
String plainTextMessage = String.format(
PLAIN_TEXT_TEMPLATE,
firstName, // %1$s
sysName, // %2$s
codeString, // %3$s: The actual 6-digit code
formattedUserAgent, // %4$s
securityEmail // %5$s
);
// 6. Subject Line
String subject = String.format("Your %s Verification Code: %d", sysName, code);
// 7. Send the Email
DMLUtils.sendEmailHTMLandPlain(
email,
htmlMessage,
plainTextMessage,
subject,
secretClient
);
}
return result;
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... tification
Мобильная версия