Skip to content

Instantly share code, notes, and snippets.

@hmnhf
Last active November 13, 2020 09:20
Show Gist options
  • Select an option

  • Save hmnhf/da95ecd81240bbe96836 to your computer and use it in GitHub Desktop.

Select an option

Save hmnhf/da95ecd81240bbe96836 to your computer and use it in GitHub Desktop.

Revisions

  1. hmnhf revised this gist Nov 13, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions mandrillapp_invalid_sender_characters.rb
    Original file line number Diff line number Diff line change
    @@ -6,10 +6,10 @@

    Mail.defaults do
    delivery_method :smtp, {
    :port => 25,
    :address => "smtp.mandrillapp.com",
    :user_name => ENV["MANDRILL_USERNAME"],
    :password => ENV["MANDRILL_PASSWORD"]
    port: 25,
    address: "smtp.mandrillapp.com",
    user_name: ENV["MANDRILL_USERNAME"],
    password: ENV["MANDRILL_PASSWORD"]
    }
    end

  2. hmnhf revised this gist Nov 13, 2020. 1 changed file with 14 additions and 17 deletions.
    31 changes: 14 additions & 17 deletions mandrillapp_invalid_sender_characters.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    # I was encountering this exception
    # Net::SMTPServerBusy: 401 4.1.7 Bad sender address syntax
    # First I searched to see if there's any documentation around this issue,
    # didn't find anything, so I wrote this snippet to find those invalid characters
    # I was encountering this exception: Net::SMTPServerBusy: 401 4.1.7 Bad sender address syntax
    # First I searched to see if there's any documentation around this issue but didn't find anything,
    # so I wrote this snippet to find those invalid characters.

    require 'mail'

    @@ -14,19 +13,17 @@
    }
    end

    def check_if_char_is_invalid c
    @invalid_chars ||= []

    mail = Mail.deliver do
    to ENV["MYEMAIL"]
    from "John Doe #{c} <john@doe.com>"
    subject 'A transactional email from Mandrill!'
    end
    (32..255).each_with_object([]) do |codepoint, invalid_chrs|
    chr = codepoint.chr
    begin
    Mail.deliver do
    to ENV["MYEMAIL"]
    from "John Doe #{chr} <john@doe.com>"
    subject 'A transactional email from Mandrill!'
    end
    rescue Net::SMTPServerBusy
    puts "invalid char: #{c}"
    @invalid_chars.push(c).uniq!
    invalid_chrs.push(chr)
    end
    end

    (32..255).each { |x| check_if_char_is_invalid x.chr }

    @invalid_chars # => ["\"", "(", ",", ":", ";", "<", ">", "["]
    # => ["\"", "(", ",", ":", ";", "<", ">", "["]
  3. hmnhf renamed this gist May 31, 2015. 1 changed file with 0 additions and 0 deletions.
  4. hmnhf renamed this gist May 31, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. hmnhf created this gist May 31, 2015.
    32 changes: 32 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    # I was encountering this exception
    # Net::SMTPServerBusy: 401 4.1.7 Bad sender address syntax
    # First I searched to see if there's any documentation around this issue,
    # didn't find anything, so I wrote this snippet to find those invalid characters

    require 'mail'

    Mail.defaults do
    delivery_method :smtp, {
    :port => 25,
    :address => "smtp.mandrillapp.com",
    :user_name => ENV["MANDRILL_USERNAME"],
    :password => ENV["MANDRILL_PASSWORD"]
    }
    end

    def check_if_char_is_invalid c
    @invalid_chars ||= []

    mail = Mail.deliver do
    to ENV["MYEMAIL"]
    from "John Doe #{c} <john@doe.com>"
    subject 'A transactional email from Mandrill!'
    end
    rescue Net::SMTPServerBusy
    puts "invalid char: #{c}"
    @invalid_chars.push(c).uniq!
    end

    (32..255).each { |x| check_if_char_is_invalid x.chr }

    @invalid_chars # => ["\"", "(", ",", ":", ";", "<", ">", "["]