{"record":{"id":"d3389bf4419b2cf0","repo":"Kareadita/Kavita","slug":"send-to-kavita-email","errorCode":null,"errorMessage":"send-to-kavita-email","messagePattern":"send-to-kavita-email","errorType":"exception","errorClass":"KavitaException","httpStatus":null,"severity":"error","filePath":"Kavita.Services/DeviceService.cs","lineNumber":104,"sourceCode":"\n            await readingProfileService.RemoveDeviceLinks(userWithDevices.Id, deviceId);\n\n            if (!unitOfWork.HasChanges()) return true;\n            if (await unitOfWork.CommitAsync(ct)) return true;\n        }\n        catch (Exception ex)\n        {\n            logger.LogError(ex, \"There was an issue with deleting the device, {DeviceId} for user {UserName}\", deviceId, userWithDevices.UserName);\n        }\n\n        return false;\n    }\n\n    public async Task<bool> SendTo(IReadOnlyList<int> chapterIds, int deviceId, CancellationToken ct = default)\n    {\n        var settings = await unitOfWork.SettingsRepository.GetSettingsDtoAsync(ct);\n        if (!settings.IsEmailSetupForSendToDevice())\n            throw new KavitaException(\"send-to-kavita-email\");\n\n        var device = await unitOfWork.DeviceRepository.GetDeviceById(deviceId, ct);\n        if (device == null) throw new KavitaException(\"device-doesnt-exist\");\n\n        var files = await unitOfWork.ChapterRepository.GetFilesForChaptersAsync(chapterIds, ct);\n        if (files.Any(f => f.Format is not (MangaFormat.Epub or MangaFormat.Pdf)) && device.Platform == EmailDevicePlatform.Kindle)\n            throw new KavitaException(\"send-to-permission\");\n\n        // If the size of the files is too big\n        if (files.Sum(f => f.Bytes) >= settings.SmtpConfig.SizeLimit)\n            throw new KavitaException(\"send-to-size-limit\");\n\n\n        try\n        {\n            device.UpdateLastUsed();\n            unitOfWork.DeviceRepository.Update(device);\n            await unitOfWork.CommitAsync(ct);","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/Kareadita/Kavita/blob/9c3e5400007f8a0282f7d883f2ad5e71716e514d/Kavita.Services/DeviceService.cs#L86-L122","documentation":"Thrown by DeviceService.SendTo when the server's email/SMTP settings are not configured for send-to-device. IsEmailSetupForSendToDevice() returns false when either SmtpConfig.Host or SmtpConfig.SenderAddress is empty. This is a pre-flight check that fires before any device or file validation.","triggerScenarios":"Admin has not configured SMTP settings in the server configuration; SMTP host was set but sender address is blank; settings were partially configured and saved; SMTP config was cleared during a settings reset.","commonSituations":"Fresh Kavita installation where email was never set up; admin cleared SMTP settings to troubleshoot email issues; migration to a new server where SMTP config wasn't carried over; environment variable for SMTP host not set in container deployments.","solutions":["Navigate to Server Settings > Email and configure the SMTP Host and Sender Address fields","Verify the SMTP Host value is not empty and is the correct server hostname or IP","Set the Sender Address to a valid email address that the SMTP server will accept","Save settings and test the email configuration before retrying send-to-device"],"exampleFix":"// In Server Settings UI, set:\n// SMTP Host: smtp.example.com\n// SMTP Port: 587\n// Sender Address: kavita@example.com\n// Then Save and retry Send to Device.","handlingStrategy":"validation","validationCode":"// Check SMTP configuration before allowing send-to-device:\n// var settings = await unitOfWork.SettingsRepository.GetSettingsDtoAsync(ct);\n// if (!settings.IsEmailSetupForSendToDevice()) {\n//     return BadRequest(\"Email is not configured. Set up SMTP in Server Settings first.\");\n// }","typeGuard":null,"tryCatchPattern":"// try {\n//     await deviceService.SendTo(chapterIds, deviceId, ct);\n// } catch (KavitaException ex) when (ex.Message == \"send-to-kavita-email\") {\n//     return BadRequest(new { error = \"SMTP email is not configured. Go to Server Settings > Email.\" });\n// }","preventionTips":["Configure SMTP settings during initial server setup before enabling send-to-device","Validate SMTP configuration completeness in the UI and disable send-to-device until configured","Provide a clear UI hint on the send-to-device screen when email is not set up"],"tags":["device","email","smtp","configuration","send-to-device"],"backgroundTag":null,"analyzedSha":"9c3e5400007f8a0282f7d883f2ad5e71716e514d","analyzedAt":"2026-08-13T19:06:05.897Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}