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

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

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

    隨筆-167  評論-65  文章-0  trackbacks-0

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

    預覽:

    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

    注意點

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

    2,body部分可以

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

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

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

    image

    126的是這樣設置的:

    image

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

    image



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

    評論:
    # re: Rails Send Mail Demo2[未登錄] 2009-05-18 19:04 | tingting
    Findpassword.deliver_contact(recipient, subject, message)
    我用的時候發(fā)現(xiàn)沒有這個方法哦,只有這個deliver方法呢  回復  更多評論
      
    # re: Rails Send Mail Demo2 2009-05-19 10:21 | fl1429
    deliver_contact contact方法在model里,send mail調用的時候必須這么寫!  回復  更多評論
      
    已訪問數(shù):
    free counters
    主站蜘蛛池模板: 成人亚洲网站www在线观看| 91麻豆最新在线人成免费观看| 18禁无遮挡无码网站免费| 亚洲成aⅴ人片在线观| 999国内精品永久免费观看| 亚洲日本国产精华液| 男女做羞羞的事视频免费观看无遮挡| 亚洲欧洲国产成人精品| 中文字幕免费在线看线人 | 国产传媒在线观看视频免费观看| 亚洲精品天堂无码中文字幕| 日韩一区二区在线免费观看 | 免费人成网站在线观看不卡| 亚洲制服中文字幕第一区| 色老头永久免费网站| 亚洲综合国产成人丁香五月激情| 成人毛片18岁女人毛片免费看| 亚洲乱妇熟女爽到高潮的片| 成人亚洲综合天堂| 久久精品国产影库免费看| 亚洲午夜久久久精品影院| 国产成在线观看免费视频| 爱情岛论坛亚洲品质自拍视频网站| 免费国产在线观看不卡| 最近免费中文字幕MV在线视频3 | 亚洲成熟xxxxx电影| 久久久久久国产a免费观看黄色大片 | 亚洲中文字幕一区精品自拍| 亚洲成a人无码av波多野按摩| aaa毛片视频免费观看| 亚洲高清在线mv| 日本免费一区尤物| 中文成人久久久久影院免费观看 | 亚洲2022国产成人精品无码区| 青青青国产在线观看免费网站| 深夜特黄a级毛片免费播放| 亚洲a一级免费视频| 在线免费观看一区二区三区| 中文字幕成人免费高清在线 | 最近中文字幕免费大全| 亚洲综合偷自成人网第页色 |