Mercurial Hosting > luan
comparison src/luan/modules/mail/SmtpCon.java @ 1275:cc3dabc05f72
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 04 Dec 2018 21:42:11 -0700 |
parents | 9fa8b8389578 |
children | 25746915a241 |
comparison
equal
deleted
inserted
replaced
1274:383f924dfe9d | 1275:cc3dabc05f72 |
---|---|
23 | 23 |
24 public final class SmtpCon { | 24 public final class SmtpCon { |
25 private final Session session; | 25 private final Session session; |
26 | 26 |
27 public SmtpCon(LuanTable paramsTbl) throws LuanException { | 27 public SmtpCon(LuanTable paramsTbl) throws LuanException { |
28 Map<Object,Object> params = new HashMap<Object,Object>(paramsTbl.asMap()); | 28 Map<Object,Object> params = paramsTbl.asMap(); |
29 Properties props = new Properties(System.getProperties()); | 29 Properties props = new Properties(System.getProperties()); |
30 | 30 |
31 String host = getString(params,"host"); | 31 String host = getString(params,"host"); |
32 if( host==null ) | 32 if( host==null ) |
33 throw new LuanException( "parameter 'host' is required" ); | 33 throw new LuanException( "parameter 'host' is required" ); |
79 } | 79 } |
80 | 80 |
81 | 81 |
82 public void send(LuanTable mailTbl) throws LuanException { | 82 public void send(LuanTable mailTbl) throws LuanException { |
83 try { | 83 try { |
84 Map<Object,Object> mailParams = new HashMap<Object,Object>(mailTbl.asMap()); | 84 Map<Object,Object> mailParams = mailTbl.asMap(); |
85 MimeMessage msg = new MimeMessage(session); | 85 MimeMessage msg = new MimeMessage(session); |
86 | 86 |
87 String from = getString(mailParams,"from"); | 87 String from = getString(mailParams,"from"); |
88 if( from != null ) | 88 if( from != null ) |
89 msg.setFrom(from); | 89 msg.setFrom(from); |
111 if( body != null ) { | 111 if( body != null ) { |
112 if( body instanceof String ) { | 112 if( body instanceof String ) { |
113 bodyPart.setText((String)body); | 113 bodyPart.setText((String)body); |
114 } else if( body instanceof LuanTable ) { | 114 } else if( body instanceof LuanTable ) { |
115 LuanTable bodyTbl = (LuanTable)body; | 115 LuanTable bodyTbl = (LuanTable)body; |
116 Map<Object,Object> map = new HashMap<Object,Object>(bodyTbl.asMap()); | 116 Map<Object,Object> map = bodyTbl.asMap(); |
117 MimeMultipart mp = new MimeMultipart("alternative"); | 117 MimeMultipart mp = new MimeMultipart("alternative"); |
118 String text = (String)map.remove("text"); | 118 String text = (String)map.remove("text"); |
119 if( text != null ) { | 119 if( text != null ) { |
120 MimeBodyPart part = new MimeBodyPart(); | 120 MimeBodyPart part = new MimeBodyPart(); |
121 part.setText(text); | 121 part.setText(text); |
144 if( body != null ) | 144 if( body != null ) |
145 mp.addBodyPart((MimeBodyPart)bodyPart); | 145 mp.addBodyPart((MimeBodyPart)bodyPart); |
146 for( Object attachment : attachmentsTbl.asList() ) { | 146 for( Object attachment : attachmentsTbl.asList() ) { |
147 if( !(attachment instanceof LuanTable) ) | 147 if( !(attachment instanceof LuanTable) ) |
148 throw new LuanException( "each attachment must be a table" ); | 148 throw new LuanException( "each attachment must be a table" ); |
149 Map<Object,Object> attachmentMap = new HashMap<Object,Object>(((LuanTable)attachment).asMap()); | 149 Map<Object,Object> attachmentMap = ((LuanTable)attachment).asMap(); |
150 Object obj; | 150 Object obj; |
151 | 151 |
152 obj = attachmentMap.remove("filename"); | 152 obj = attachmentMap.remove("filename"); |
153 if( obj==null ) | 153 if( obj==null ) |
154 throw new LuanException( "an attachment is missing 'filename'" ); | 154 throw new LuanException( "an attachment is missing 'filename'" ); |