开发者

Google App Engine Email

I use the following method to send email in the Google App Engine servlet :

  void Send_Email(String From,String To,String Message_Text)
  {
    Properties props=new Properties();
    Session session=Session.getDefaultInstance(props,null);
    try
    {
      Message msg=new MimeMessage(session);
      msg.setFrom(new InternetAddress(From,"nmjava开发者_StackOverflow.com Admin"));
      msg.addRecipient(Message.RecipientType.TO,new InternetAddress(To,"Ni , Min"));
      msg.setSubject("Servlet Message");
      msg.setText(Message_Text);
      Transport.send(msg);
    }
    catch (Exception ex)
    {
      // ...
    }
  }

But it doesn't work, have I missed anything ? Has anyone got the email function working ?


Edit : I've fixed the String/Text part, but the email function still doesn't work, it says emails were sent, but I checked my mailbox, none received. I ran it on the Google server, what's wrong ?


I figured out, I need to give it my Gmail address as sender, otherwise no email will go out.


I don't know much about Java, but maybe if you removed the try/catch stuff you could see what the error actually is?

According to the docs:

"When an application running in the development server calls the Mail service to send an email message, the message is printed to the log. The Java development server does not send the email message."

Does anything show up in the log?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜