Skip to Content
-1

Send e-mail with html5

Nov 27, 2017 at 08:44 AM

76

avatar image
Former Member

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/e70a574cbb57101494a781920e3c9d64.html

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Masayuki Sekihara
Nov 27, 2017 at 01:02 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Uwe Fetzer Nov 27, 2017 at 12:47 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Richard Zhao
Nov 28, 2017 at 02:28 AM
0

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);
Share
10 |10000 characters needed characters left characters exceeded