In my rails application I am trying to send mail using custom from address.
It works fine few times, but most of the time it doesn't work.
I am getting the following smtp error message
Net::SMTPFatalError (553 Sorry, your envelope sender is in my badmailfrom list.
):
C:/Ruby/lib/ruby/1.8/net/smtp.rb:687:in `check_response'
C:/Ruby/lib/ruby/1.8/net/smtp.rb:660:in `getok'
C:/Ruby/lib/ruby/1.8/net/smtp.rb:638:in `mailfrom'
C:/Ruby/lib/ruby/1.8/net/smtp.rb:550:in `send0'
C:/Ruby/lib/ruby/1.8/net/smtp.rb:475:in `sendmail'
/vendor/rails/actionmailer/lib/action_mailer/base.rb:638:in `perform_delivery_smtp'
Here is my sample code
In mailer.rb
def mail_to_friend(recipient_mail, sender_mail, subjects, messages, host, port)
#host = host
#port = port
recipients recipient_mail
from "#{sender_mail}" #custom from address
subject "#{subjects}"
sent_on Time.now
body :message_body => messages, :host => host, :port => port
content_type "text/html"
end
I am using Rails 2.3.5 and Ruby 1.8.6.
PS: I am not using google smtp server(using own smtp server)
Thanks in Advance
The owner of the remote SMTP server banned you (or the guy you are impersonating), I guess because you were using their server to test weird stuff without asking for permission (or because what you are doing approximates what spammers do, and you triggered an automatic ban rule).
Related
I have a rails application that makes calls to another server via net::http to retrieve documents.
I have set up Nginx with secure_link.
The nginx config has
secure_link $arg_md5,$arg_expires;
secure_link_md5 "$secure_link_expires$uri$remote_addr mySecretCode";
On the client side (which is in fact my rails server) I have to create the secure url something like:
time = (Time.now + 5.minute).to_i
hmac = Digest::MD5.base64digest("#{time}/#{file_path}#{IP_ADDRESS} mySecretCode").tr("+/","-_").gsub("==",'')
return "#{DOCUMENT_BASE_URL}/#{file_path}?md5=#{hmac}&expires=#{time}"
What I want to know is the best way to get the value above for IP_ADDRESS
There are multiple answers in SO on how to get the ip address but alot of them do not seem as reliable as actually making a request to a web service that returns the ip address of the request as this is what the nginx secure link will see (we don't want some sort of localhost address).
I put the following method on my staging server:
def get_client_ip
data=Hash.new
begin
data[:ip_address]=request.ip
data[:error]=nil
rescue Exception =>ex
data[:error]=ex.message
end
render :json=>data
end
I then called the method from the requesting server:
response = Net::HTTP.get_response(URI("myserver.com/web_service/get_client_ip"))
if response.class==Net::HTTPOK
response_hash=JSON.parse response.body
ip=response_hash["ip_address"] unless response_hash[:error]
else
#deal with error
end
After getting the ip address successfully I just cached it and did not keep on calling the web service method.
so I'm using the Pusher Heroku Add-on for my application. The application has live notifications, so when a user receives a message he will see a pop up notification saying "new message". However, In production I am getting the below error:
Firefox can't establish a connection to the server at ws://ws.pusherapp.com/app/b1cc5d4f400faddcb40b?protocol=7&client=js&version=2.1.6&flash=false.
Reload the page to get source for: http://js.pusher.com/2.1/pusher.min.js
And here's the Pusher controller:
class PusherController < ApplicationController
protect_from_forgery :except => :auth # stop rails CSRF protection for this action
def auth
Pusher.app_id = ENV['PUSHER_APP_ID']
Pusher.key = ENV['PUSHER_KEY']
Pusher.secret = ENV['PUSHER_SECRET']
if current_user && params[:channel_name] == "private-user-#{current_user.id}"
response = Pusher[params[:channel_name]].authenticate(params[:socket_id])
render :json => response
else
render :text => "Not authorized", :status => '403'
end
end
end
And I'm using the figaro gem to push the keys to heroku.
What am I doing wrong?
Kind regards
JS
That looks like a problem with Javascript, rather than Rails
We've got pusher working very well with one of our production apps, and it works by firstly having the pusher gem installed, allowing you to call the pusher JS files from your layout:
#app/views/layouts/application.html.erb
<%= javascript_include_tag "http://js.pusher.com/2.1/pusher.min.js" %>
Rails
You may also wish to put the pusher initialization code into an initializer:
#config/initializers/pusher.rb
Pusher.url = ENV["PUSHER_URL"]
Pusher.app_id = ENV["PUSHER_APP_ID"]
Pusher.key = ENV["PUSHER_KEY"]
Pusher.secret = ENV["PUSHER_SECRET"]
This will ensure app-wide connectivity, rather than controller-specific (allowing for greater flexibility)
Firefox can't establish a connection to the server at ws://ws.pusherapp.com/app/b1cc5d4f400faddcb40b?protocol=7&client=js&version=2.1.6&flash=false.
Reload the page to get source for: http://js.pusher.com/2.1/pusher.min.js
This doesn't necessarily mean anything is wrong. it just means that an unsecured WebSocket connection couldn't be established. Pusher's fallback strategy should result in a successful connection being established via either HTTP fallback (HTTP or HTTPS) or via WSS (a secure WebSocket connection).
Failed connection attempts are logged as console errors. There's nothing that can be done about that.
To test this you can bind to connection events and ensure that you are indeed connecting. The pusher-js JavaScript logging will also help determine what's happening.
You can also try http://test.pusher.com/
According to my problem I posted here: mailer error in production only I decided to create a small scaffold app to find a solution.
The problem:
I can't send (newsletter)email with smtp in production, but it works perfectly in development.
You can find the app in my github repository.
I just created a contact_messages scaffold and a simple mailer.
The error log after clicking on the submit button to receive email:
Started POST "/contact_messages" for 194.XXX.XX.XXX at 2013-02-26 19:43:59 +0000
Processing by ContactMessagesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xx0nxxJ2xwxxJavvZ278EUy2TABjD9CixxNcxDqwg=",
"contact_message"=>{"name"=>"test", "email"=>"test#testemail.com", "message"=>"test1"}, "commit"=>"Create Contact message"}
Rendered contact_mailer/confirmation.text.erb (0.3ms)
Sent mail to test#testemail.com (38ms)
Completed 500 Internal Server Error in 100ms
Errno::ECONNREFUSED (Connection refused - connect(2)):
app/controllers/contact_messages_controller.rb:46:in `create'
The emails get saved, they are listed in the index. So the database should work fine.
I'm using Ubuntu 12.04, Apache, Phusion Passenger, SMTP with Gmail Account.
Could this probably be a server issue, or am I doing something wrong in the app?
I'm using fail2ban and denyhost. Could these tools block smtp?
Any help will be appreciated, thanks!
By default, Rails sends email by connecting to the target SMTP server. Try using sendmail instead. Add this in your config/initializers/production.rb:
config.action_mailer.delivery_method = :sendmail
I solved my problem with a change to a new passwort (api-key) from mandrill. Still don't know what the problem was, because with the old one it worked in development mode...
The working setting:
YourApp::Application.configure do
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:enable_starttls_auto => true,
:user_name => "MANDRILL_USERNAME",
:password => "MANDRILL_PASSWORD", # SMTP password is any valid API key
:authentication => 'login'
}
I want to render received emails (via SMTP Server) that are stored in my DB and my question is:
Is there a gem that provides rendering html_part, text_part from incoming email (received via SMTP Server) or something that can help to render an email depending which type it is (HTML, TEXT) ?
with best regards
Hannes
yes there is a very beautiful gem mailcatcher here github link
Instructions:
1) install the gem configure it by replacing your default setting with
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
2) open terminal type mailcatcher enter.
3) send email.
4) now open browser and go to this address localhost:1080.
you will see that you have received email.
MailView from 37signals allows you to render Mailer objects and view them from your browser.
I'm currently hosting both my rails app and a faye-server app on Heroku. The faye server has been cloned from here (https://github.com/ntenisOT/Faye-Heroku-Cedar) and seems to be running correctly. I have disabled websockets, as they are not supported on Heroku. Despite the claim on Faye's site that:
"Faye clients and servers transparently support cross-domain communication, so your client can connect to a server on any domain you like without further configuration."
I am still running into this error when I try to post to a faye channel:
XMLHttpRequest cannot load http://MYFAYESERVER.herokuapp.com. Origin http://MYAPPURL.herokuapp.com is not allowed by Access-Control-Allow-Origin.
I have read about CORS and tried implementing some solutions outlined here: http://www.tsheffler.com/blog/?p=428 but have so far had no luck. I'd love to hear from someone who:
1) Has a rails app hosted on Heroku
2) Has a faye server hosted on Heroku
3) Has the two of them successfully communicating with each other!
Thanks so much.
I just got my faye and rails apps hosted on heroku communicating within the past hour or so... here are my observations:
Make sure your FAYE_TOKEN is set on all of your servers if you're using an env variable.
Disable websockets, which you've already done... client.disable(...) didn't work for me, I used Faye.Transport.WebSocket.isUsable = function(_,c) { c(false) } instead.
This may or may not apply to you, but was the hardest thing to track down for me... in my dev environment, the port my application is running on will be tacked onto the end of the specified hostname for my faye server... but this appeared to cause a failure to communicate in production. I worked around that by creating a broadcast_server_uri method in application_controller.rb that handles inclusion of a port when necessary, and then use that anywhere I spin up a new channel.
....
class ApplicationController < ActionController::Base
def broadcast_server
if request.port.to_i != 80
"http://my-faye-server.herokuapp.com:80/faye"
else
"http://my-faye-server.herokuapp.com/faye"
end
end
helper_method :broadcast_server
def broadcast_message(channel, data)
message = { :ext => {:auth_token => FAYE_TOKEN}, :channel => channel, :data => data}
uri = URI.parse(broadcast_server)
Net::HTTP.post_form(uri, :message => message.to_json)
end
end
And in my app javascript, including
<script>
var broadcast_server = "<%= broadcast_server %>"
var faye;
$(function() {
faye = new Faye.Client(broadcast_server);
faye.setHeader('Access-Control-Allow-Origin', '*');
faye.connect();
Faye.Transport.WebSocket.isUsable = function(_,c) { c(false) }
// spin off your subscriptions here
});
</script>
FWIW, I wouldn't stress about setting Access-Control-Allow-Origin as it doesn't seem to be making a difference either way - I see XMLHttpRequest cannot load http://... regardless, but this should still works well enough to get you unblocked. (although I'd love to learn of a cleaner solution...)
Can't say I have used Rails/Faye on Heroku but have you tried setting the Access-Control-Allow-Origin header to something like Access-Control-Allow-Origin: your-domain.com?
For testing you could also do Access-Control-Allow-Origin: * to see if that helps
Custom headers
Some services require the use of additional HTTP headers to connect to
their Bayeux server. You can add these headers using the setHeader()
method, and they will be sent if the underlying transport supports
user-defined headers (currently long-polling only).
client.setHeader('Authorization', 'OAuth abcd-1234');
Source: http://faye.jcoglan.com/browser.html
So try client.setHeader('Access-Control-Allow-Origin', '*');