用户注册时如何发送特定电子邮件 ID 的自动回复? [英] How send automatic reply on particular email id when an user registers?

查看:28
本文介绍了用户注册时如何发送特定电子邮件 ID 的自动回复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JSP 中创建了一个注册表单,其中包含一个电子邮件地址输入字段.当用户提交表单时,用户必须在他/她的电子邮件地址上获得自动回复.我怎样才能做到这一点?

I have created a registration form in JSP with an input field for email address. When user submits the form, then the user must get an auto-reply on his/her email address. How can I achieve this?

推荐答案

你的问题不是很清楚.让我得到正确的要求;只有在成功注册后,您才需要代码才能向用户发送电子邮件.正确吗?

Your question is not very clear. Let me get the requirement right; you need the code to send an email to the user only on successful registration. correct?

在您的 servlet(在提交操作时调用)中,

In your servlet(which is invoked on submit action),

if(user input is valid){
  Step1: registerUser();
  Step2: send confirmationEmail();
} else {
  Step3: Exception case
}

发送电子邮件方法最好将请求发送到 JMS(队列)以将电子邮件发送给所需的用户.以下是发送电子邮件的片段.

Send email method would ideally send the request to an JMS(queue) to send the email to the desired user. Below is a snippet to send an email.

//Sample java code to send email

public void sendEmail(){

        try{

            Properties props = null;

                if (props == null) {
                        props = System.getProperties();
                }

                props.put("mail.smtp.host", "<server host name>");

                Session session = Session.getInstance(props, null);

                MimeMessage message = new MimeMessage(session);

                message.setFrom(new InternetAddress("<from email id>"));            

                message.addRecipients(Message.RecipientType.CC, "<Registered user email id>");          

                message.setSubject("<Subject of the email>");

                message.setContent("<Content of the email>", "text/plain");         

                Transport.send(message);    

                    logger.info("Sent Email :" + 
                        "From :" + message.getFrom() +
                        "To:" + message.getAllRecipients() +
                        "Subject:" + message.getSubject() );

            } catch(Exception ex){
                ex.printStackTrace();
            }       
        }

这篇关于用户注册时如何发送特定电子邮件 ID 的自动回复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆