通过带有Sendgrid on Rails 3.1.3的smtp发送时,电子邮件中的非法字符

时间:2012-04-09 19:35:24

标签: ruby-on-rails-3.1 heroku sendgrid

我正在从gmail导入联系人列表,并使用复选框选择返回的电子邮件,并在用户选择后向其发送邀请。当我查看我的日志时,输出的电子邮件格式正确,一切似乎都很好。

当我在Sendgrid上查看我的电子邮件活动时,我看到附加到电子邮件地址的其他字符因此导致其失败。我没有任何问题使用sendmail与我的其他邮件发送电子邮件,但这个似乎添加了这些额外的字符,我不知道它们来自哪里。

还有其他人看到过这种情况吗?或者有关于如何解决这个问题的建议?

预期结果 电子邮件:test@gmail.com

实际结果 电子邮件:“test@gmail.com”@ i04-01

user_mailer文件

def invitation(email_addresses)
@host = ((Rails.env == "production") ? "http://www.test.com" : "http://localhost:3000")
attachments.inline['people.jpg'] = File.read("#{Rails.root}/app/assets/images/people.jpg")
#attachments.inline['people.jpg'] = File.read("#{Rails.root}/app/assets/images/Girl.jpeg")
email_addresses.each do |email|
  mail(:to => email, :subject => "Hello from test!")
end

user_controller

def import
#@user = User.find(params[:id])
#@users = User.find(session[:user_id])
begin
  @sites = {"gmail" => Contacts::Gmail, "yahoo" => Contacts::Yahoo, "hotmail" => Contacts::Hotmail}
  @contacts = @sites[params[:from]].new(params[:login], params[:password]).contacts
  @users, @no_users = [], []
  @contacts.each do |contact|
    #if u = User.find(:first , :conditions => @users.email = �#{contact[1]}� , :include =>[:user])
    if u = User.find(:first, :conditions => "email = '#{contact[1]}'")
      @users << u
    else
      @no_users << {:name => contact[0], :email => contact[1]}
    end
  end

  #if @contacts.save
  #end

  respond_to do |format|
    format.html { render :template => 'shared/_contact_list', :layout => false }
    format.xml { render :xml => @contacts.to_xml }
  end
end

def send_bulk_mail
name_email =[]
email_addresses=[]
names=[]
post=params[:post]
post.each do |k,v|
  if v=="1"
    name_email << k
  end
end
name_email.each do |n|
  email_addresses << n.split(",")[1]
end
UserMailer.invitation(email_addresses).deliver

端 感谢

0 个答案:

没有答案