jeudi 13 août 2015

Net::SMTPSyntaxError (501 Sender syntax err$ Heroku

Random issue with my ruby on rails application out of the blue. I'm getting a 501 error each time a user tries to submit the form. This error does not occur when I'm running the app locally, it only occurs when I push to Heroku.

heroku logs --tail(The error shows up below)

Net::SMTPSyntaxError (501 Sender syntax err$│ app/controllers/contact_controller.rb:38:$

def tour_create
@message = Message.new(params[:message])
@message.type = "Tour"
@message.save

if @message.valid?
          UserMailer.tour_signup(@message).deliver
          flash[:notice] = "Thank you for your interest in  You'll receive an email from us confirming your participation in this Thursday's tour within 24- 48 hours."
          redirect_to("/tour/confirmed")
      else
        flash.now.alert = "Please fill all fields."
        render :tour_new
          end
  end

usermailer.rb

Emails are taken out for privacy reasons.

class UserMailer < ActionMailer::Base
  default from: "string"


  def tour_signup(message)
    @message = message

        mail(:to => message.email, 
            :cc => "string that is an email goes here", 
            :subject => message.first_name + ", Let's Tour This Wednesday"
        )
  end

  def orientation_signup(message, date)
    @message = message
    @date = date

    mail(:to => message.email, 
      :cc => "email", 
      :subject => message.first_name + ",string that gets sent to users inbox
    )
  end

  def ask_a_question(message)
    @message = message

        mail(:to => "emailstringgoes here", 
            :subject => message.first_name + " Has A Question"
        )
  end

  def trial_kickoff_confirmation_to_user(message, type)
    @message = message
    @date = message.event_time.strftime("%l:%M %P, on %A, %B %-d")
    @type = type
    type_subject = type.split.map(&:capitalize).join(' ')

        mail(:to => message.email,
            :subject => "Your #{type_subject} Has Been Scheduled!"
        )
  end

  def trial_kickoff_confirmation_to_hosts(message, type)
    @message = message
    @date = message.event_time.strftime("%l:%M %P, on %A, %B %-d")
    @type = type
    type_subject = type.split.map(&:capitalize).join(' ')

    if type == 'kick-off day'
      email = 'email'
    else
      email = 'email'
    end

        mail(:to => email, 
            :subject => "#{type_subject} for " + message.first_name + " " + message.last_name
        )   
  end

  def new_member_from_batchbook(member, password)
    @member = member
    @password = password

    mail(:to => @email, 
      #:cc => "emailgoes here string", 
      :subject => "#{@first_name}, finish your profile at string.com!"
    )
  end


  def member_import_notification message, status
    @message = message
    @status = status
    mail(
      :to => 'email@string.com', 
      #:cc => "email@string.com", 
      :subject => "#{@message['first_name']}, import to email@string.com #{status}!"
    )
  end

  def no_new_member_notification
    mail(
      :to => 'email@string.com', 
      #:cc => "email@string.com", 
      :subject => "Import ran. No new members!"
    )
  end
end

.ruby-env

bash -c 'echo "POSTMARK_API_TOKEN=`heroku config:get POSTMARK_API_TOKEN`" >> .env'
bash -c 'echo "POSTMARK_SMTP_SERVER=`heroku config:get POSTMARK_SMTP_SERVER`" >> .env'
bash -c 'echo "POSTMARK_INBOUND_ADDRESS=`heroku config:get POSTMARK_INBOUND_ADDRESS`" >> .env'

Procfile web: bundle exec rails server -p 3000

Production.rb file

 Hub::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false


  # set what the default url for the mailer
  config.action_mailer.default_url_options = { :host => 'www.examplesite.com' }

  # Compress JavaScripts and CSS
  config.assets.compress = true
  config.assets.js_compressor  = :uglifier

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = true

  # Pre-compile for production
  config.assets.precompile += Ckeditor.assets

  # Generate digests for assets URLs
  config.assets.digest = true

  # Action mailer
  ActionMailer::Base.delivery_method = :smtp
  ActionMailer::Base.perform_deliveries = true  
  ActionMailer::Base.raise_delivery_errors = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify

end

Aucun commentaire:

Enregistrer un commentaire