Hot to get the next value from array of a hash : **File: database.rb** Here I connect to the database and loop over the rows in table `rcpt`. Then I store the value in `row["email"]`. The table stores two values: `id` with primary key, auto_increment and `email`.



    require 'mysql2'

    class Db
  
      def con
        @db_host = "localhost"
        @db_user = "root"
        @db_pass = "password"
        @db_name = "table_db"
    
        client = Mysql2::Client.new(:host => @db_host, :unsername => @db_user, :password => @db_pass, :database => @db_name)
        rcpt = client.query("SELECT * from rcpt")
        rcpt.each do |row|
          row["email"]
        end
      end
    end

Ouput of `con` method without ["email"]:

    {"id"=>01, "email"=>"example1@example.com"}
    {"id"=>02, "email"=>"example2@example.com"}

Output of `con` method with ["email"]:

    example1@example.com
    example2@example.com

**File: message_class.rb** Here I create the method `pull_rcpt` which then stores `row["email"]`. Then I'm trying to use the `pull_rcpt` method in `message` heredoc. Now comes my problem: in the `To:` field, I'm trying to pass the users email address I'm currently sending to, so it should change with the receiving email address. It still uses the email address of the first contact in the array/Db. What am I doing wrong?

    require 'dkim'
    require './database'

    class Email
  
      def pull_rcpt
        rcpt = Db.new
        rcpt.con
      end
  
      def data
        Dkim::domain      = 'example.com'
        Dkim::selector    = 'mail'
        Dkim::private_key = open('/path/to/keys/example.com/mail.private').read 
    
        message = <<~MESSAGE
        From: Eva <test@example.com>
        To: Dani <#{pull_rcpt[0]["email"]}>
        MIME-Version: 1.0
        Content-Type: text/html
        Content-Transfer-Encoding: 8bit
        Subject: Test Subject
    
        This is an email message.
        <h1>Test</h1>
        MESSAGE
       end
    end

**File: mailer.rb** In my mailer_class I have two method's `rcpt_to` and `message` which contains an array `contacts`, which holds the values of `row["email"]`. 

    def rcpt_to
    #conn zu DB & take rcpt
      contacts = []
      contacts = Db.new
      contacts.con
    end

    def message 
    #message
      message = Email.new
    end

A few lines later I use the methods as follows: 

    @protocol = {rcpt_to: [rcpt["email"]], data: Dkim.sign(message.data)}

Here is the email raw header from the second email address/value in the database:
 
     From: Eva <test@example.com>
     To: Dani <example1@example.com> <--- This should be example2(second value in hash and second entry in database) not example1
     MIME-Version: 1.0
     Content-Type: text/html
     Content-Transfer-Encoding: 8bit
     Subject: Test Subject
     Content-Length: 40

Any help would be appreciated. Thanks in advance. Sorry for my language, its not my native. 