cancel
Showing results for 
Search instead for 
Did you mean: 

Send e-mail with html5

Former Member
0 Kudos

I would like to set the logic to send mail with html5 application.

Is it also possible in scp environment?

Remarks:

I checked what I can do with java application.

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

Accepted Solutions (0)

Answers (3)

Answers (3)

richard-zhao
Employee
Employee
0 Kudos

Hello, Ryuji If you frontend is base on UI5 and backend is JAVA. I would like to show you an example how to send the email by using Java.

If your application is base on Spring platform then you could use API from spring-context-support.jar and mail.jar.

@Component
 public class EmailSendService implements IEmailSendService {
     private String host;
     private String username;
     private String password;
 
     public boolean sendText(String email[], String title, String text) {
         try {
             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); 
 
             Properties prop = new Properties();
             prop.put("mail.smtp.auth", "true"); 
             prop.put("mail.smtp.timeout", "25000");
             senderImpl.setJavaMailProperties(prop);
             senderImpl.send(mailMessage);
             System.out.println(" 邮件发送成功.. ");
             return true;
         } catch (Exception e) {
             e.printStackTrace();
             return false;
         }
     }
 
     public boolean sendHtml(String email[], String title, String html) {
         try {
             JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
             senderImpl.setHost(this.host);
             MimeMessage mailMessage = senderImpl.createMimeMessage();
             MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage);
             messageHelper.setTo(email);
             messageHelper.setFrom(this.username);
             messageHelper.setSubject(title);
             messageHelper.setText(html, true);
             senderImpl.setUsername(this.username); 
             senderImpl.setPassword(this.password); 
             Properties prop = new Properties();
             prop.put("mail.smtp.auth", "true"); 
             prop.put("mail.smtp.timeout", "25000");
             senderImpl.setJavaMailProperties(prop);
             senderImpl.send(mailMessage);
             System.out.println("邮件发送成功..");
             return true;
         } catch (Exception e) {
             e.printStackTrace();
             return false;
         }
     }
 
     public void setHost(String host) {
         this.host = host;
     }
 
     public void setUsername(String username) {
         this.username = username;
     }
 
     public void setPassword(String password) {
         this.password = password;
     }
 
     public boolean sendText(String email, String title, String text) {
         return this.sendText(new String[]{email}, title, text);
     }
 
     public boolean sendHtml(String email, String title, String html) {
         return this.sendHtml(new String[]{email}, title, html);
     }
 
 }

And if you just want to use pure JAVA you could use API JavaMail.

 Properties 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");
 Authenticator auth = new Authenticator() {
 public PasswordAuthentication getPasswordAuthentication({
    return new PasswordAuthentication("15953185712@163.com", "czxsqm521");
            }
        };
 Session session = Session.getInstance(props, auth);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("15953185712@163.com"));
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(email));
message.setSubject("email send successfully");
message.setContent(emailMsg, "text/html;charset=utf-8");
Transport.send(message);
masa_139
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Ryuji,

I guess you are talking about client side Javascript.

Take a look at this. Can JavaScript email a form? and Can I use HTML5 to send a client-side email?

If you are talking about client side popup, take a look at URLHelper.

Regards,

Masa

UweFetzer_se38
Active Contributor
0 Kudos

If only your UI5-App is running on SCP and your backend is an ABAP Stack it is easy to send mails. Just search around here on the SAP Community and you'll find the answer on how to send mails with ABAP.

If you tagged your question accidently with "ABAP Development", please delete this tag.