Code Monkey home page Code Monkey logo

project_test_for_email's Introduction

  1. 创建project和question表

  2. 增加邮件发送功能

  3. 创建question的时候就发送邮件

log:

Started POST "/questions" for 127.0.0.1 at 2023-06-06 22:09:22 +0800
Processing by QuestionsController#create as TURBO_STREAM
  Parameters: {"authenticity_token"=>"[FILTERED]", "question"=>{"title"=>"test", "content"=>"test", "status"=>"已分发", "level"=>"低", "assigned_to"=>"[email protected]", "start_day"=>"2023-06-06T01:39", "project_id"=>"1"}, "commit"=>"Create Question"}
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  TRANSACTION (0.1ms)  BEGIN
  ↳ app/controllers/questions_controller.rb:27:in `block in create'
  Project Load (0.1ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/questions_controller.rb:27:in `block in create'
  Question Create (0.2ms)  INSERT INTO "questions" ("title", "content", "status", "level", "assigned_to", "start_day", "created_at", "updated_at", "project_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"  [["title", "test"], ["content", "test"], ["status", "已分发"], ["level", "低"], ["assigned_to", "[email protected]"], ["start_day", "2023-06-06 01:39:00"], ["created_at", "2023-06-06 14:09:22.769603"], ["updated_at", "2023-06-06 14:09:22.769603"], ["project_id", 1]]
  ↳ app/controllers/questions_controller.rb:27:in `block in create'
  TRANSACTION (0.4ms)  COMMIT
  ↳ app/controllers/questions_controller.rb:27:in `block in create'
  Rendering layout layouts/mailer.html.erb
  Rendering question_mailer/question_assigned.html.erb within layouts/mailer
  Rendered question_mailer/question_assigned.html.erb within layouts/mailer (Duration: 0.6ms | Allocations: 174)
  Rendered layout layouts/mailer.html.erb (Duration: 1.0ms | Allocations: 394)
QuestionMailer#question_assigned: processed outbound mail in 5.1ms
Delivered mail [email protected] (11.0ms)
Date: Tue, 06 Jun 2023 22:09:22 +0800
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: =?UTF-8?Q?=E6=82=A8=E6=9C=89=E4=B8=80=E9=A1=B9=E6=96=B0=E7=9A=84=E4=BB=BB=E5=8A=A1?=
 =?UTF-8?Q?_-_#<Question:0x00007fbb4e2fb118>?=
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf=
-8" />
    <style>
      /* Email styles need to be inline */
    </style>
  </head>

  <body>
    <h1>=E6=82=A8=E6=9C=89=E4=B8=80=E9=A1=B9=E6=96=B0=E7=9A=84=E4=BB=BB=E5=
=8A=A1</h1>
<p>=E4=BB=BB=E5=8A=A1=EF=BC=9Atest</p>
<p>=E9=A1=B9=E7=9B=AE=EF=BC=9Abaogong</p>

  </body>
</html>

Redirected to http://localhost:3333/questions/5
Completed 302 Found in 23ms (ActiveRecord: 0.8ms | Allocations: 10869)


进入console 进行测试

rails c -e p Loading production environment (Rails 7.0.5) irb(main):002:0> a = Question.last => #<Question:0x00007fa5a97a9aa8 ... irb(main):003:0> QuestionMailer.question_assigned(a).deliver_now Rendered question_mailer/question_assigned.html.erb within layouts/mailer (Duration: 0.6ms | Allocations: 254) Rendered layout layouts/mailer.html.erb (Duration: 1.1ms | Allocations: 499) Delivered mail [email protected] (1622.1ms) => #<Mail::Message:45740, Multipart: false, Headers: <Date: Tue, 06 Jun 2023 22:46:59 +0800>, <From: [email protected]>, <To: [email protected]>, <Message-ID: [email protected]>, <Subject: 您有一项新的任务 - #Question:0x00007fa5a97a9aa8>, <Mime-Version: 1.0>, <Content-Type: text/html>, <Content-Transfer-Encoding: quoted-printable>> irb(main):004:0>

然后发送成功了。

在浏览器(develop)环境下创建新的question,也成功收到一封邮件。nice.


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.