Mandrill - No message exists with id - ruby

I'm having an issue using the mandrill API for ruby and i'm not sure if it's a lack of ruby/api understanding on my part of if there's an issue with the mandrill api.
I have this method which sends an email with mandrill, and then I make another api call using the id returned from mandrill.messages.send to make another call to mandrill to get the email header message-id so i can store that in a db table.
Why am I getting the error Mandrill::UnknownMessageError (No message exists with the id '64fba1cce24942dea1ada4f905fd7871'): when the id clearly exists as seen in the comments for the logging events?
# Sends an email to all users for the account_id on the issue
def send_email
require 'mandrill'
...
mandrill = Mandrill::API.new Mandrill::API_KEY
# Email contents
message = {
:subject => self.name,
:from_name => self.account.subdomain,
:text => self.description,
:to => [{
:email => user.email,
:name => user.name
}],
:text => self.description,
:from_email => "noreply#myapp.com",
:headers => {
'reply-to' => 'update#myapp.com'
}
}
results = mandrill.messages.send message # Send email through mandrill
# Loop through results of sent email
results.each do |result|
logger.debug "result id = #{result['_id']}" # LOGS result id = 64fba1cce24942dea1ada4f905fd7871
logger.debug "result = #{result}" # LOGS result = {"email"=>"tomcaflisch#gmail.com", "status"=>"sent", "_id"=>"64fba1cce24942dea1ada4f905fd7871", "reject_reason"=>nil}
id = result['_id'] # Mandrill's internal id from api call results that sent the email
# CAUSES Mandrill::UnknownMessageError (No message exists with the id '64fba1cce24942dea1ada4f905fd7871'):
info = mandrill.messages.content id # Get info for sent email with a specific mandrill id
end
end

I think you just have to give it a little bit of time.

I am facing the same error on messages.info(id).
However, search('*') is finding all messages sent but not providing correct status information.
I think the following snippet of gem code is getting 500 status (instead of 200) when messages.info(id) is called:
def call(url, params={})
params[:key] = #apikey
params = JSON.generate(params)
r = #session.post(:path => "#{#path}#{url}.json", :headers => {'Content-Type' => 'application/json'}, :body => params)
cast_error(r.body) if r.status != 200
return JSON.parse(r.body)
end
Also, gem code is hosted on bitbucket instead of more common github. Not sure how to raise an issue there for support.
Sorry can't be of much help but thought I should share my experience also to get more visibility for the problem.

Related

Gmail: Ruby gem google-api-client broken?

Nobody has encountered this?
I can get the email message object (Google::Apis::GmailV1::Message) but other Message attributes just returns Nil. Only id, thread_id seems to be returned.
SCOPE = Google::Apis::GmailV1::AUTH_GMAIL_MODIFY
service = Google::Apis::GmailV1::GmailService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
user_msgs = service.list_user_messages('me',
{:include_spam_trash => false, :label_ids => ['INBOX'], :q => "is:unread"})
user_msgs.messages.each do |msg|
puts "CLASS: #{msg.class}" # Google::Apis::GmailV1::Message
puts "MESSAGE ID: #{msg.id}" # WORKS I get the email ID
msg_part = msg.payload
puts "MSGPART: #{msg_part.class}" # NIL !!!, All other attributes are also NIL
end
So basically I do get the email with the correct ID, but that's about it, all methods or attributes of the GmailV1::Message class is Nil. I also tried changing the SCOPE to MODIFY and same result.
Attributes that just returns Nil:
internal_date label_ids payload raw size_estimate snippet
Also noticed that github project linked in their documentation opens a 404 page on some.
Might be due to Google now forcing developers to have publicly available apps reviewed first: https://developers.google.com/gmail/api/auth/about-auth (see the notification in the blue box with the star)

Can't create class object in quickbooks using quickbooks ruby gem

I would like to create Account object for Quickbooks. However, when I try:
service.create(account_object)
It returns the error:
Quickbooks::InvalidModelException: Classification is not included in the list
I tried putting in one of the default values(https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/account), but it returns the same error..
Classification in account will be something like Liability, Revenue, Expense or Asset etc.
Go to this URL https://developer.intuit.com/docs/api/accounting/Account
look at AccountType section => Child attributes
It have all list of classification and account type that we can use while creating accounts
You can use below sample code to create account
begin
oauth_client = OAuth::AccessToken.new($qb_oauth_consumer, token, secret)
service = Quickbooks::Service::Account.new(:access_token => oauth_client, :company_id => realm_id)
new_account = Quickbooks::Model::Account.new(:name => 'Undeposited money', :account_type => 'Other Current Asset', :classification => 'Asset' )
create_acccount = service.create(new_account)
rescue Exception => e
# e.message will show response of quickbooks for you request
puts e.message
# e.message.inspect will show logs
puts e.backtrace.inspect
end

undefined method error on local server where method works on live server-Why is the new code breaking it?

I'm trying to integrate our app with MailChimp, so that new users get added to our mailing list and new paid subscribers get updated on the mailing list as paid subscribers (we have a MERGE VARS for that). In order to test that the list is updating properly when the customer pays for a subscription, I'm trying to run the code with the test server for Stripe. (I inherited the code after we had tested it, so I haven't done this before.)
I'm running into an undefined method error, and I can't figure out where it's coming from, since it is working just fine on the live site, and I haven't changed that part of the code.
in the initializer file stripe.rb, I changed Stripe.api_key
="the live secret key" to the test secret key, just subbing in the other key.
I did the same in our layout/application.html.erb file (where we put the initial call to Stripe per Stripe's instructions), swapping out the public live key for the public test key.
In the account_controller processing method (which is called for payment processing on the Stripe token and updating our server with the type of subscription.):
def processing
begin
if params[:coupon][0] != "_"
#coupon = params[:coupon]
else
#coupon = nil
end
customer = Stripe::Customer.create(
:email => current_user.email,
:card => params[:stripeToken],
:plan => params[:plan],
:coupon => #coupon
)
current_user.subscription = params[:plan]
current_user.stripe_id = customer.id
current_user.canceled = false
current_user.save!
rescue Stripe::CardError => e
flash[:error] = e.message
end
#only this code is new, from here:
#for gibbon updating subscription status
gb=Gibbon::API.new
email=current_user.email
subscription=user.subscription
updated_date=user.updated_at.strftime('%B %d, %Y')
gb.lists.subscribe({:id => "our list id", :email => {:email => "#{email}"}, :merge_vars => {:SUB => "test", :UPDATE => "#{updated_date}"}, :update_existing=>true , :double_optin => false, :send_welcome=> false})
#to here is new code
current_user
respond_to do |format|
format.html { redirect_to account_confirmation_path }
end
end
I'm getting a "NoMethodError in AccountController#processing
undefined method 'canceled=' for #User:an-id-here" (note the #User: an id here is in pointy brackets, but those aren't showing up here.)
error. This code works on the live site, so that makes me think it must be something I've done here. Canceled is a column on our User model, which is a boolean indicating whether they've canceled. It is not set as attr_accesible or attr_accessor, but as I said, that code hasn't changed and works on the live site.
I'm not sure what the problem is and I feel like I don't have enough information to start figuring it out. The server is only recording the same error message as shows up in the browser. (Oh, and I'm running the test code only on my local server, not the live server).
What might be causing the undefined method error? I'm not seeing anything in the code I changed that should do it.

Using Twilio api how to send the verification code as sms

I am using twillio api to send sms from my application . Its working fine . But I need to send the verification code as sms to verify his phone number and then need to submit registration from in my rails project.
Can any one please provide the sample example using twilio to verify the code.
Thanks
Here is an example of Twilio
require 'rubygems'
require 'twilio-ruby'
account_sid = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
client = Twilio::REST::Client.new account_sid, auth_token
from = '+441702806101' # Your Twilio number
friends = {
'+447908232434' => 'David'
}
friends.each do |key, value|
client.account.sms.messages.create(
:from => from,
:to => key,
:body => "#{value} you are working 30/04/2013 - CX1"
)
puts "Sent message to #{value}"
end
See a code complete tutorial in Ruby:
https://www.twilio.com/docs/tutorials/walkthrough/account-verification/ruby/rails
Hope this helps

Attempt at authenticated SMTP in Ruby

I've looked at all the SMTP ruby-docs and can't figure out where I'm going wrong:
def send(username, password, data, toAddress, fromAddress)
smtp = Net::SMTP.new('my.smtp.host', 25)
smtp.start('thisisunimportant', username, password, "plain") do |sender|
sender.send_message(data, fromAddress, toAddress)
end
end
send(user, pass, rcpt, "Hey!")
Gives an unexpected kind of error:
/usr/lib/ruby/1.9.1/net/smtp.rb:725:in authenticate': wrong number of arguments (3 for 4) (ArgumentError)
from /usr/lib/ruby/1.9.1/net/smtp.rb:566:indo_start'
from /usr/lib/ruby/1.9.1/net/smtp.rb:531:in start'
from gmx_pop.rb:24:insend'
from gmx_pop.rb:30:in `'
I've tried kicking my computer a couple times but the problem persists.
Here's a description of the Net::SMTP#start call:
http://ruby-doc.org/stdlib-1.9.1/libdoc/net/smtp/rdoc/Net/SMTP.html#method-i-start
the page mentions that you can just do SMTP.start to do everything at once.
Look like you are missing the port parameter. Try port 587 for secure authentication, if that doesn't work, port 25. (check the tutorial mentioned below)
Your call should look like this:
message_body = <<END_OF_EMAIL
From: Your Name <your.name#gmail.com>
To: Other Email <other.email#somewhere.com>
Subject: text message
This is a test message.
END_OF_EMAIL
server = 'smtp.gmail.com'
mail_from_domain = 'gmail.com'
port = 587 # or 25 - double check with your provider
username = 'your.name#gmail.com'
password = 'your_password'
smtp = Net::SMTP.new(server, port)
smtp.enable_starttls_auto
smtp.start(server,username,password, :plain)
smtp.send_message(message_body, fromAddress, toAddress) # see note below!
Important:
Please note that you need to add To: , From: , Subject: headers to your message_body!
the Message-Id: and Date: headers will be added by your SMTP server
Check also:
Tutorial : http://www.java-samples.com/showtutorial.php?tutorialid=1121
the source code for Net::SMTP under ~/.rvm/src/ruby-1.9.1*/lib/net/smtp.rb
(Ruby) Getting Net::SMTP working with Gmail...?
Another way to send emails from Ruby:
You can use the ActionMailer gem from Rails to send emails from Ruby (without Rails).
At first this seems like overkill, but it makes it much easier, because you don't have to format the message body with To: , From: , Subject: , Date: , Message-Id: Headers.
# usage:
# include Email
#
# TEXT EMAIL :
# send_text_email( 'sender#somewhere.com', 'sender#somewhere.com,receiver#other.com', 'test subject', 'some body text' )
# HTML EMAIL :
# send_html_email( 'sender#somewhere.com', 'sender#somewhere.com,receiver#other.com', 'test subject', '<html><body><h1>some title</h1>some body text</body></html>' )
require 'action_mailer'
# ActionMailer::Base.sendmail_settings = {
# :address => "Localhost",
# :port => 25,
# :domain => "yourdomain.com"
# }
ActionMailer::Base.smtp_settings = { # if you're using GMail
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => "your-username#gmail.com"
:password => "your-password"
:authentication => "plain",
:enable_starttls_auto => true
}
class SimpleMailer < ActionMailer::Base
def simple_email(the_sender, the_recepients, the_subject, the_body , contenttype = nil)
from the_sender
recipients the_recepients
subject the_subject
content_type contenttype == 'html' ? 'text/html' : 'text/plain'
body the_body
end
end
# see http://guides.rails.info/action_mailer_basics.html
# for explanation of dynamic ActionMailer deliver_* methods.. paragraph 2.2
module Email
# call this with a message body formatted as plain text
#
def send_text_email( sender, recepients, subject, body)
SimpleMailer.deliver_simple_email( sender , recepients , subject , body)
end
# call this with an HTML formatted message body
#
def send_html_email( sender, recepients, subject, body)
SimpleMailer.deliver_simple_email( sender , recepients , subject , body, 'html')
end
endsubject , body, 'html')
end
end
e.g. the code above works if you want to use Gmail's SMTP server to send email via your Gmail account.. Other SMTP servers may need other values for :port, :authentication and :enable_starttls_auto depending on the SMTP server setup
Try this code
Net::SMTP.smtp.start('my.smtp.host', 25, 'mail.from.domain', username, password, :plain) do |smtp|
smtp.send_message data, fromAddress, toAddress
end

Resources