发送带有html5的电子邮件

2020-08-18 06:33发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)我想设置使用html5应用程序发...

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


我想设置使用html5应用程序发送邮件的逻辑。

在scp环境中也可以吗?

备注:

我检查了我可以用Java应用程序做什么。

https://help.sap.com/viewer/ cca91383641e40ffbe03bdc78f00f681/Cloud/ja-JP/e70a574cbb57101494a781920e3c9d64.html

3条回答
Aaron 3364
2020-08-18 07:11

您好,Ryuji如果您的前端基于UI5,而后端则是JAVA。 我想向您展示一个示例,说明如何使用Java发送电子邮件。

如果您的应用程序基于Spring平台,则可以使用spring-context-support.jar和mail.jar中的API。

 @Component
  公共类EmailSendService实现IEmailSendService {
      私有字符串主机;
      私有字符串用户名;
      私有字符串密码;
 
      public boolean sendText(String email [],字符串标题,字符串文本){
          尝试{
              JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
              senderImpl.setHost(this.host);
              SimpleMailMessage mailMessage = new SimpleMailMessage();
              mailMessage.setTo(email);
              mailMessage.setFrom(IDNMailHelper.toIdnAddress(this.username));
              mailMessage.setSubject(title);
              mailMessage.setText(text);
 
              senderImpl.setUsername(this.username);
              senderImpl.setPassword(this.password);
 
              属性prop = new Properties();
              prop.put(" mail.smtp.auth"," true");
              prop.put(" mail.smtp.timeout"," 25000");
              senderImpl.setJavaMailProperties(prop);
              senderImpl.send(mailMessage);
              System.out.println("邮件发送成功..");
              返回true;
          } catch(Exception e){
              e.printStackTrace();
              返回false;
          }
      }
 
      public boolean sendHtml(String email [],String title,String html){
          尝试{
              JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
              senderImpl.setHost(this.host);
              MimeMessage mailMessage = senderImpl.createMimeMessage();
              MimeMessageHelper messageHelper =新的MimeMessageHelper(mailMessage);
              messageHelper.setTo(email);
              messageHelper.setFrom(this.username);
              messageHelper.setSubject(title);
              messageHelper.setText(html,true);
              senderImpl.setUsername(this.username);
              senderImpl.setPassword(this.password);
              属性prop = new Properties();
              prop.put(" mail.smtp.auth"," true");
              prop.put(" mail.smtp.timeout"," 25000");
              senderImpl.setJavaMailProperties(prop);
              senderImpl.send(mailMessage);
              System.out.println("邮件发送成功..");
              返回true;
          } catch(Exception e){
              e.printStackTrace();
              返回false;
          }
      }
 
      public void setHost(String host){
          this.host =主机;
      }
 
      公共无效setUsername(String用户名){
          this.username =用户名;
      }
 
      公共无效setPassword(字符串密码){
          this.password =密码;
      }
 
      public boolean sendText(String email,String title,String text){
          返回this.sendText(new String [] {email},标题,文本);
      }
 
      public boolean sendHtml(字符串电子邮件,字符串标题,字符串html){
          返回this.sendHtml(new String [] {email},title,html);
      }
 
  }
 

如果您只想使用纯JAVA,则可以使用API​​ JavaMail。

属性props = new Properties();
  props.setProperty(" mail.transport.protocol"," SMTP");
  props.setProperty(" mail.smtp.host"," smtp.163.com");
  props.setProperty(" mail.smtp.port"," 25");
  props.setProperty(" mail.smtp.auth"," true");
  props.setProperty(" mail.smtp.timeout"," 1000");
  身份验证器auth =新的Authenticator(){
  public PasswordAuthentication getPasswordAuthentication({
     返回新的PasswordAuthentication(" 15953185712@163.com"," czxsqm521");
             }
         };
  会话会话= Session.getInstance(props,auth);
 消息消息=新的MimeMessage(会话);
 message.setFrom(new InternetAddress(" 15953185712@163.com"));
 message.setRecipient(MimeMessage.RecipientType.TO,新的InternetAddress(电子邮件));
 message.setSubject("电子邮件发送成功");
 message.setContent(emailMsg," text/html; charset = utf-8");
 Transport.send(message);
 

一周热门 更多>