Rails 发送邮件

Python012

Rails 发送邮件,第1张

首先需要在 config/application.rb 中配置发送邮件的相关配置

使用脚手架工具生成邮件视图模板,脚手架工具会为我们自动创建发送邮件的方法、视图模板、测试以及预览组件

打开 app/mailers/application_mailer.rb 文件,替换 default from 后面的参数为发件人邮箱,如:

打开 app/mailers/welcome_mailer.rb 文件,编辑收件人和邮件主题,如:

在 app/views/welcome_mailer 文件夹中创建 welcome_mailer.html.erb 文件,使用 html 来编写邮件的视图。如下:

然后,你就可以测试发送邮件了。

Rails 可以支持预览邮件内容。打开 test/mailers/previews/welcome_mailer_preview.rb 文件。添加与发送邮件同名方法,如:

然后启动你的 Rails 应用,访问 http://localhost:3000/rails/mailers/welcome_mailer/welcome_mail 进行预览。

关于发送邮件更多的资料可以在 https://ruby-china.github.io/rails-guides/action_mailer_basics.html 中查看。

您好,很高兴为您解答。

1、安装action_mailer_tls

2、在environment.rb中加入

Ruby代码

ActionMailer::Base.delivery_method = :smtp #使用smtp发送邮件

ActionMailer::Base.default_charset = "UTF-8" #指定发送邮件时使用的字符集

ActionMailer::Base.server_settings = {

:address =>"smtp.gmail.com", #使用的邮件服务器

:port =>587,#邮件服务器的端口号

:domain =>"xxx.com", #暂时忽略

:authentication =>:login,

:user_name =>"[email protected]", #使用邮件服务器的帐号

:password =>"yourpassword", #使用邮件服务器的密码

}

如若满意,请点击右侧【采纳答案】,如若还有问题,请点击【追问】

希望我的回答对您有所帮助,望采纳!

本文实例讲述了python通过get,post方式发送http请求和接收http响应的方法。分享给大家供大家参考。具体如下:

测试用CGI,名字为test.py,放在apache的cgi-bin目录下:

#!/usr/bin/python

import cgi

def main():

print "Content-type: text/html\n"

form = cgi.FieldStorage()

if form.has_key("ServiceCode") and form["ServiceCode"].value != "":

print "<h1>Hello",form["ServiceCode"].value,"</h1>"

else:

print "<h1>Error! Please enter first name.</h1>"

main()

python发送post和get请求

get请求:

使用get方式时,请求数据直接放在url中