{"record":{"id":"548c7eb0b7feac1e","repo":"antiwork/gumroad","slug":"please-enter-a-valid-kindle-email-address","errorCode":null,"errorMessage":"Please enter a valid Kindle email address","messagePattern":"Please enter a valid Kindle email address","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"app/modules/sendable_to_kindle.rb","lineNumber":12,"sourceCode":"# frozen_string_literal: true\n\nmodule SendableToKindle\n  extend ActiveSupport::Concern\n\n  included do\n    # `url_redirect` provides the purchase context needed to locate the\n    # buyer-specific stamped copy of a stamp-enabled PDF. Without it the\n    # original (un-watermarked) file would be emailed, bypassing the\n    # seller's PDF stamping setting.\n    def send_to_kindle(kindle_email, url_redirect: nil)\n      raise ArgumentError, \"Please enter a valid Kindle email address\" unless kindle_email.match(KINDLE_EMAIL_REGEX)\n\n      CustomerMailer.send_to_kindle(kindle_email, id, url_redirect&.id).deliver_later(queue: \"critical\")\n    end\n  end\nend\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/antiwork/gumroad/blob/afeacbd394069a1cbf0c6c50ee8e900925050370/app/modules/sendable_to_kindle.rb#L1-L18","documentation":"Raised as ArgumentError by SendableToKindle#send_to_kindle (app/modules/sendable_to_kindle.rb:12) when the supplied kindle_email does not match KINDLE_EMAIL_REGEX (config/initializers/aws.rb:34). The regex is strict about the domain: the address must end in @kindle.com (case-insensitive), be 3–255 characters, and have no leading/consecutive dots — so a Gmail/Yahoo address fails even though it is a valid email. The method then enqueues CustomerMailer.send_to_kindle on the critical queue, optionally passing the url_redirect whose id locates the buyer-specific stamped PDF.","triggerScenarios":"Calling purchase.send_to_kindle(email) / library-item send-to-Kindle with any address not ending in @kindle.com — regular email addresses, typos like 'user@kindle.co', empty strings, or addresses with consecutive dots. User.kindle_email is validated against the same regex on save.","commonSituations":"Buyers entering their normal email instead of the @kindle.com address from their Kindle device settings; whitespace or a second @; front-end accepting any RFC-5322 address without the domain restriction.","solutions":["Instruct the user to enter their @kindle.com address (Kindle device settings → Send-to-Kindle email); validate the same pattern client-side before submitting.","Strip whitespace and downcase before validating.","Rescue ArgumentError around send_to_kindle and re-prompt for a corrected address instead of a 500."],"exampleFix":"# before\npurchase.send_to_kindle(params[:email]) # ArgumentError for non-@kindle.com\n\n# after\nemail = params[:email].to_s.strip.downcase\nunless email.match?(KINDLE_EMAIL_REGEX)\n  return { error: \"Please enter a valid Kindle email address (must end in @kindle.com).\" }\nend\npurchase.send_to_kindle(email)","handlingStrategy":"validation","validationCode":"email = kindle_email.to_s.strip.downcase\nreturn { error: 'Enter your @kindle.com address.' } unless email.match?(KINDLE_EMAIL_REGEX)","typeGuard":null,"tryCatchPattern":"begin\n  purchase.send_to_kindle(email, url_redirect:)\nrescue ArgumentError => e\n  render json: { message: e.message }, status: :unprocessable_entity # re-prompt for a @kindle.com address\nend","preventionTips":["Validate the @kindle.com suffix client-side — a valid generic email is not enough for this API.","Strip and downcase input before matching; reject consecutive/leading dots and strings over 255 chars.","Tell users where to find the address: Kindle device settings → Send-to-Kindle email."],"tags":["kindle","email-validation","argumenterror","delivery","rails","regex"],"backgroundTag":"invalid-email-format","analyzedSha":"afeacbd394069a1cbf0c6c50ee8e900925050370","analyzedAt":"2026-08-21T17:58:52.159Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}