diff --git a/src/main/lib/smtp-error.ts b/src/main/lib/smtp-error.ts new file mode 100644 index 0000000..e5a28df --- /dev/null +++ b/src/main/lib/smtp-error.ts @@ -0,0 +1,28 @@ +import type { ImapCredentials } from '../../shared/types/account' + +export function formatSmtpError(error: unknown, credentials: ImapCredentials): string { + const message: string = error instanceof Error ? error.message : String(error) + const host: string = credentials.smtpHost ?? credentials.host.replace(/^imap\./i, 'smtp.') + const port: number = credentials.smtpPort ?? 587 + const secure: boolean = credentials.smtpSecure ?? port === 465 + const mode: string = secure ? 'SSL/TLS' : 'STARTTLS' + const normalized: string = message.toLowerCase() + let hint: string = '' + if (normalized.includes('wrong version number') || normalized.includes('unknown protocol')) { + hint = 'Проверьте SMTP-порт и режим шифрования: обычно 465 — SSL/TLS, 587 — STARTTLS (переключатель SSL/TLS выключен).' + } else if (normalized.includes('certificate') || normalized.includes('self signed')) { + hint = 'Не удалось проверить сертификат SMTP-сервера. Проверьте имя сервера и доверие к сертификату. Для корпоративного сервера с самоподписанным сертификатом есть отдельная настройка аккаунта.' + } else if (normalized.includes('legacy renegotiation')) { + hint = 'SMTP-сервер использует устаревшее согласование TLS. Требуется обновление TLS на сервере или адрес другого SMTP-сервера у администратора.' + } else if (normalized.includes('ssl') || normalized.includes('tls')) { + hint = 'Не удалось установить защищённое SMTP-соединение. Проверьте порт, режим шифрования и настройки TLS сервера.' + } + return [`SMTP ${host}:${port} (${mode})`, hint, message].filter(Boolean).join('\n') +} + +export class SmtpSendError extends Error { + constructor(error: unknown, credentials: ImapCredentials) { + super(formatSmtpError(error, credentials), { cause: error }) + this.name = 'SmtpSendError' + } +} diff --git a/src/main/providers/imap.provider.ts b/src/main/providers/imap.provider.ts index 0e43ed7..5b3c324 100644 --- a/src/main/providers/imap.provider.ts +++ b/src/main/providers/imap.provider.ts @@ -1,3 +1,5 @@ +import { getAccountEmail } from '@shared/utils/account-email' +import { SmtpSendError } from '../lib/smtp-error' import { buildComposeAttachments } from '../lib/compose-attachments' import { ImapFlow } from 'imapflow' import { simpleParser } from 'mailparser' @@ -407,9 +409,7 @@ export class ImapProvider implements IEmailProvider { }) // Если email хранится без домена (только логин) — достраиваем из IMAP-хоста - const emailAddress = this.config.email.includes('@') - ? this.config.email - : `${this.config.email}@${creds.host.replace(/^[^.]+\./, '')}` + const emailAddress = getAccountEmail(this.config) // Имя отправителя: await-им промис из connect() — гарантирует что имя готово const senderName = await this.senderNamePromise @@ -440,6 +440,8 @@ export class ImapProvider implements IEmailProvider { inReplyTo: compose.inReplyTo, references: compose.references, attachments: buildComposeAttachments(compose) + }).catch((error: unknown): never => { + throw new SmtpSendError(error, creds) }) // Сохраняем в папку Sent (best-effort) diff --git a/src/renderer/src/components/ComposeEditor.vue b/src/renderer/src/components/ComposeEditor.vue index db46f1f..e5e2c3e 100644 --- a/src/renderer/src/components/ComposeEditor.vue +++ b/src/renderer/src/components/ComposeEditor.vue @@ -1,6 +1,7 @@ + + + + + + + + {{ isActualSize ? 'Вписать в окно' : 'Исходный размер' }} + + Закрыть + + + + + + + + + + diff --git a/src/renderer/src/components/preview/MessageBody.vue b/src/renderer/src/components/preview/MessageBody.vue index a9499ab..6b732e9 100644 --- a/src/renderer/src/components/preview/MessageBody.vue +++ b/src/renderer/src/components/preview/MessageBody.vue @@ -1,5 +1,6 @@