Question from Prabhu on Apr 30 at 2:20 AM Hi, I am using the below code to send email. Without providing the password i am able to send the email using SMTP server. In the from field if i provide the wrong email ID it is send the email. Why it is happening like that.. Code: public void CreateEmail { Properties properties = new Properties(); properties.put("mail.smtp.host", smtpserver); properties.put("mail.smtp.port", smtpserverport); Session session = Session.getDefaultInstance(properties, null); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(From)); message.setRecipient(Message.RecipientType.TO, new InternetAddress(To)); //message.setRecipient(Message.RecipientType.CC, new InternetAddress(CC)); //message.setRecipient(Message.RecipientType.BCC, new InternetAddress(Bcc)); message.setSubject(Subject); message.setSentDate(new Date()); // Set the email message text. MimeBodyPart messagePart = new MimeBodyPart(); messagePart.setText(bodyText); // Set the email attachment file MimeBodyPart attachmentPart = new MimeBodyPart(); FileDataSource fileDataSource = new FileDataSource(filename) { @Override public String getContentType() { return "application/octet-stream"; } }; attachmentPart.setDataHandler(new DataHandler(fileDataSource)); attachmentPart.setFileName(fileDataSource.getName( )); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messagePart); multipart.addBodyPart(attachmentPart); message.setContent(multipart); Transport.send(message); System.out.println("Message Sent"); } catch (MessagingException e) { e.printStackTrace(); } } | Reply to this email to post your response. __.____._ | _.____.__ |
No comments:
Post a Comment