在scala playframework(2.6)slick中向Gmail发送邮件

时间:2018-08-24 18:22:26

标签: scala playframework slick

我正在尝试将邮件发送到我的gmail帐户。 我收到“电子邮件发送”的回复。但是我没有收到任何邮件。 我正在使用Scal Playframework(2.6)

public class CustomTextInputLayout extends TextInputLayout {

    public CustomTextInputLayout(Context context) {
        this(context, null);
    }

    public CustomTextInputLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomTextInputLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        registerFocusChangeListener();
    }

    private void registerFocusChangeListener() {
        getEditText().setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                String text = getEditText().getText().toString();
                boolean isEmpty = TextUtils.isEmpty(text);
                if (!isEmpty) { // EditText is not empty, doesn't matter whether it is focused or unfocused
                    setHintTextAppearance(R.style.TextAppearance_Dark);
                } else {  // EditText is empty
                    setHintTextAppearance(R.style.TextAppearance_Light);
                }
            }
        });
    }
}

这远远不是我所做的

控制器类

libraryDependencies += "com.typesafe.play" %% "play-mailer" % "6.0.0"
libraryDependencies += "com.typesafe.play" %% "play-mailer-guice" % "6.0.0"

我已经在Application.conf中添加了它

package controllers
import play.api.libs.mailer._
import java.io.File
import java.io.File
import java.io.InputStream
import play.api.Environment
import org.apache.commons.mail.EmailAttachment
import play.api.libs.mailer._
import play.api.mvc.{AbstractController, Action, Controller, ControllerComponents}
import akka.http.scaladsl.model.HttpHeader.ParsingResult.Ok
import org.apache.commons.mail.EmailAttachment
import javax.inject.Inject
import play.api.libs.json.Json
class MailController  @Inject()(mailer: MailerClient, environment: Environment) extends Controller {

  def sendWithCustomMailer = Action {
  //  val mailer = new SMTPMailer(SMTPConfiguration("typesafe.org", 1234))
   // val id = mailer.send(Email("Simple email", "Mister FROM <abhinaykumar499@gmail.com>"))

    val emailfrom="xxxxxx@gmail.com"
    val emailto="yyyyyyyyy@gmail.com"
val subject ="Simple Email"
    val bodytext="A text message";

    val email = Email("Simple email", ""+emailfrom+"", Seq(""+emailto+""), bodyText = Some("A text message"))
    mailer.send(email)

    Ok(s"Email  sent!")
  }

1 个答案:

答案 0 :(得分:0)

我认为您错误地配置了主机部件。您写了smtp.host = "smtp.gmail.com",但正确的值是host = "smtp.gmail.com"

在我的项目中,谷歌smtp的工作配置如下:

play {
  mailer {
    host = "smtp.gmail.com"
    port = 587
    tls = yes
    user = "xxxxxx@gmail.com"
    password = "xxxxxxx"
  }
}