<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-167  評(píng)論-65  文章-0  trackbacks-0

    上一遍已經(jīng)介紹了簡(jiǎn)單的rails發(fā)送mail 的demo,這個(gè)demo介紹rails發(fā)送text/html格式的郵件

    預(yù)覽:

    image

    步驟:

    1,看我上遍的介紹安裝smtp_tls,然后在environment.rb最后中添加

    ActionMailer::Base.default_content_type = "text/html"

    2,model

    class Findpassword < ActionMailer::Base 
      def contact(recipient, subject, message)
        @subject = subject
        @recipients = recipient
        @from = 'no-reply@yourdomain.com'
        @sent_on = Time.now
          @body["title"] = 'This is title'
        @body["email"] = 'sender@yourdomain.com'
        @body["message"] = message
        @headers = {}
       # @headers = {content_type => 'text/html'}
      end
    end

    3,controller

    class FindpasswordController < ApplicationController
      def index
          render :file => 'app\views\findpassword\index.rhtml'
       end
      def sendmail
        email = params["email"]
          recipient = email["recipient"]
          subject = email["subject"]
          message = email["message"]
        puts recipient + subject + message
        Findpassword.deliver_contact(recipient, subject, message)
        return if request.xhr?
        render :text => 'Email send successfully'
      end

    end

    4,view

    views/findpassword/index.rhtml

    <h1>Send Email</h1>
    <% form_tag :action => 'sendmail' do %>
    <p><label for="email_subject">Subject</label>:
    <%= text_field 'email', 'subject' %></p>
    <p><label for="email_recipient">Recipient</label>:
    <%= text_field 'email', 'recipient' %></p>
    <p><label for="email_message">Message</label><br/>
    <%= text_area 'email', 'message' %></p>
    <%= submit_tag "Send" %>
    <%  end   %>

    views/findpassword/contact.rhtml

    Hi!
    You are having one email message from <font color="red"><%= @email %></font><br/>
    with a tilte <font color="red"><%= @title %></font><br/>
    and following is the message:
    <font color="red"><%= @message %></font><br/>
    please visit  website:
    <a href="http://m.tkk7.com/fl1429">http://m.tkk7.com/fl1429</a>
    Thanks

    5,發(fā)送郵件

    http://localhost:3000/findpassword/index

    注意點(diǎn)

    1,使用text/html格式發(fā)送郵件,不是通過(guò)@headers起到效果的,而是通過(guò)ActionMailer::Base.default_content_type = "text/html" 配置

    2,body部分可以

      @body["title"] = 'This is title'
        @body["email"] = 'sender@yourdomain.com'
        @body["message"] = message

    這么寫,也可以按照我上遍那樣寫成hash格式的

    3,還記得上一遍說(shuō)道@from不起到作用,我還苦于在網(wǎng)上沒找到結(jié)果,突然我發(fā)現(xiàn)時(shí)如此的簡(jiǎn)單,一般郵件都自帶設(shè)置發(fā)件人名稱的功能(在個(gè)人賬戶處),例如gmail的是下圖這樣設(shè)置的:

    image

    126的是這樣設(shè)置的:

    image

    收到郵件后就是這樣了,發(fā)件人處就是現(xiàn)實(shí)自己設(shè)置的名稱:

    image



    write by feng
    posted on 2009-05-04 18:40 fl1429 閱讀(972) 評(píng)論(2)  編輯  收藏 所屬分類: Rails

    評(píng)論:
    # re: Rails Send Mail Demo2[未登錄] 2009-05-18 19:04 | tingting
    Findpassword.deliver_contact(recipient, subject, message)
    我用的時(shí)候發(fā)現(xiàn)沒有這個(gè)方法哦,只有這個(gè)deliver方法呢  回復(fù)  更多評(píng)論
      
    # re: Rails Send Mail Demo2 2009-05-19 10:21 | fl1429
    deliver_contact contact方法在model里,send mail調(diào)用的時(shí)候必須這么寫!  回復(fù)  更多評(píng)論
      
    已訪問(wèn)數(shù):
    free counters
    主站蜘蛛池模板: 伊人久久综在合线亚洲2019| 亚洲а∨天堂久久精品9966| 四虎成年永久免费网站| 激情五月亚洲色图| 亚洲国产香蕉人人爽成AV片久久 | 亚洲毛片一级带毛片基地| 毛片免费观看网址| 国产vA免费精品高清在线观看| 无码欧精品亚洲日韩一区| 成人免费午夜视频| 日韩av无码免费播放| 最新亚洲卡一卡二卡三新区| 亚洲精品WWW久久久久久| 18禁美女裸体免费网站| 羞羞漫画小舞被黄漫免费| 亚洲国产精品第一区二区 | 久久精品国产亚洲AV无码娇色| 午夜寂寞在线一级观看免费| 黄网站免费在线观看| 亚洲av无码有乱码在线观看| 久久久久久亚洲精品中文字幕| 成年女人色毛片免费看| 美女视频黄的免费视频网页| 亚洲AV无码AV吞精久久| 亚洲第一页中文字幕| 日韩亚洲变态另类中文| 日韩精品视频免费在线观看| 久久99精品国产免费观看| 精品久久亚洲一级α| 亚洲欧洲视频在线观看| 欧洲亚洲国产清在高| yy6080亚洲一级理论| 97无码免费人妻超级碰碰碰碰 | 无码中文字幕av免费放dvd| 国产成人精品亚洲一区| 亚洲一区二区三区久久| 亚洲国产高清在线| 亚洲精品无码鲁网中文电影| 亚洲成av人片一区二区三区| 热久久精品免费视频| 国产大片线上免费观看|