Module: TempmailSdk::Providers::GoneboxEmail
- Defined in:
- lib/tempmail_sdk/providers/gonebox_email.rb
Overview
gonebox.email 渠道实现 一次性临时邮箱服务,无需认证
Constant Summary collapse
- CHANNEL =
"gonebox-email"- BASE_URL =
"https://api.gonebox.email/api/v1"- HEADERS =
{ "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " \ "(KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36", "Accept" => "application/json", "Content-Type" => "application/json" }.freeze
Class Method Summary collapse
Class Method Details
.generate_email ⇒ EmailInfo
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tempmail_sdk/providers/gonebox_email.rb', line 20 def generate_email resp = Http.post( "#{BASE_URL}/inboxes", headers: HEADERS, json: { "domain" => "gonebox.email" }, timeout: 15 ) resp.raise_for_status body = resp.json raise "gonebox-email: create failed" unless body.is_a?(Hash) && body["success"] data = body["data"] raise "gonebox-email: invalid data" unless data.is_a?(Hash) address = data["address"].to_s raise "gonebox-email: missing address" if address.empty? # expiresAt 为秒级时间戳,转为毫秒 expires_at = nil raw_expires = data["expiresAt"] if raw_expires begin expires_at = raw_expires.to_i * 1000 rescue StandardError # 忽略 end end EmailInfo.new(channel: CHANNEL, email: address, token: "", expires_at: expires_at) end |
.get_emails(token, email) ⇒ Array<Email>
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/tempmail_sdk/providers/gonebox_email.rb', line 54 def get_emails(token, email) address = email.to_s.strip raise "gonebox-email: missing email" if address.empty? headers = HEADERS.reject { |k, _| k == "Content-Type" } resp = Http.get("#{BASE_URL}/inboxes/#{address}/messages", headers: headers, timeout: 15) return [] if resp.status_code == 404 resp.raise_for_status body = resp.json return [] unless body.is_a?(Hash) && body["success"] data = body["data"] return [] unless data.is_a?(Hash) = data["messages"] return [] unless .is_a?(Array) && !.empty? .select { |m| m.is_a?(Hash) }.map do |msg| raw = { "id" => msg["id"].to_s, "from" => (msg["from"] || msg["sender"]).to_s, "to" => address, "subject" => msg["subject"].to_s, "text" => (msg["text"] || msg["body_plain"]).to_s, "html" => (msg["html"] || msg["body_html"]).to_s, "date" => (msg["date"] || msg["received_at"]).to_s, "is_read" => false, "attachments" => [] } Normalize.normalize_email(raw, address) end end |