Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to all...As i am new to satckoverflow... I am not able to find exact way to add appropriate comments.... </p> <p>Here I am not trying to send mails via gmail server... I am just trying to send to some gmail user. with this code i am able to send mails to any one within the organization... but not to people outside the organization.</p> <p>any ways... I found the solution to my problem with "Prophesy Awaits" suggestion... I modified my code as below:</p> <pre><code> package com.trx; import java.util.Properties; import javax.activation.DataHandler; import javax.activation.DataSource; import javax.activation.FileDataSource; import javax.mail.Address; import javax.mail.Authenticator; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Multipart; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; public class MultiMimes { public static void main(String[] args) throws Exception{ Properties props = System.getProperties(); props.setProperty("mail.smtp.host", "mymailserver"); props.put("mail.smtp.port", "25"); props.put("mail.smtp.auth", "true"); props.put("mail.debug", "true"); Authenticator auth = new SMTPAuthenticator(); Session session = Session.getDefaultInstance(props, auth); Message message = new MimeMessage(session); try{ message.setSubject("I am a multipart text/html email" ); Address toAddress =new InternetAddress("my gmail address"); Address fromAddress =new InternetAddress("my organization address"); message.setFrom(fromAddress); message.addRecipient(Message.RecipientType.TO, toAddress); MimeMultipart multipart1 = new MimeMultipart("alternative"); // Create text message part MimeBodyPart textPart = new MimeBodyPart(); textPart.setContent("am text", "text/plain"); textPart.setHeader("MIME-Version" , "1.0" ); textPart.setHeader("Content-Type" , textPart.getContentType() ); System.out.println("textPart.getContentType():"+textPart.getContentType()); // Create html part MimeBodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent("&lt;html&gt;&lt;body&gt;&lt;b&gt;am html&lt;/b&gt;&lt;/body&gt;&lt;/html&gt;", "text/html"); htmlPart.setHeader("MIME-Version" , "1.0" ); htmlPart.setHeader("Content-Type" , "text/html" ); System.out.println("htmlPart.getContentType():"+htmlPart.getContentType()); //adding multiparts to message multipart1.addBodyPart(textPart); multipart1.addBodyPart(htmlPart); message.setContent(multipart1); //sending message Transport.send(message); System.out.println("mail sent successfully"); }catch(AddressException ae){ System.out.println("address exception"); ae.printStackTrace(); } catch(MessagingException e){ System.out.println("message exception"); e.printStackTrace(); } } } </code></pre> <p>and i used same SMTPAuthenticator class provided by him... now i am able to send the mails form my organizations mailserver to any email id... Thanks again.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload