Whats SMTP/POP3  host server address in JavaMail

Hello friends,
I came to know that we could send mail through Java through JavaMail
I downloaded some eg code ( for sending mail to some one )
I downloaded the mail.jar and activation.jar (and put it in right palce where it was asked to)
I am using java 1.6 SE
what i could not understand is what is
POP3 server
SMTP server
How / What to put server address in the code
Please help me. Here is the below code
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.util.Properties;
public class MailClient
     public void sendMail(String mailServer, String from, String to,
                             String subject, String messageBody,
                             String[] attachments) throws
MessagingException, AddressException
          // Setup mail server
         Properties props = System.getProperties();
         props.put("mail.smtp.host", mailServer);
         // Get a mail session
         Session session = Session.getDefaultInstance(props, null);
         // Define a new mail message
         Message message = new MimeMessage(session);
        /// System.out.println(" 1");
         message.setFrom(new InternetAddress(from));
         message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
         message.setSubject(subject);
         // Create a message part to represent the body text
         BodyPart messageBodyPart = new MimeBodyPart();
         messageBodyPart.setText(messageBody);
         //use a MimeMultipart as we need to handle the file attachments
         Multipart multipart = new MimeMultipart();
         //add the message body to the mime message
         multipart.addBodyPart(messageBodyPart);
         // add any file attachments to the message
         addAtachments(attachments, multipart);
         // Put all message parts in the message
         message.setContent(multipart);
         // Send the message
         Transport.send(message);
     protected void addAtachments(String[] attachments, Multipart multipart)
                     throws MessagingException, AddressException
         for(int i = 0; i<= attachments.length -1; i++)
             String filename = attachments;
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
//use a JAF FileDataSource as it does MIME type detection
DataSource source = new FileDataSource(filename);
attachmentBodyPart.setDataHandler(new DataHandler(source));
//assume that the filename you want to send is the same as the
//actual file name - could alter this to remove the file path
attachmentBodyPart.setFileName(filename);
//add the attachment
multipart.addBodyPart(attachmentBodyPart);
public static void main(String[] args)
try
     MailClient client = new MailClient();
String server="pop3.mydomain.com";
String from="[email protected]";
String to = "[email protected]";
String subject="Test";
String message="Testing";
String[] filenames =
{"c:\\somefile.txt"};
client.sendMail(server,from,to,subject,message,filenames);
System.out.println(" Mail Has been sent");
catch(Exception e)
e.printStackTrace(System.out);
} and the error i get after running this is
javax.mail.MessagingException: Could not connect to SMTP host: pop3.mydomain.com, port: 25;
  nested exception is:
     java.net.ConnectException: Connection timed out: connect
     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
     at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
     at javax.mail.Service.connect(Service.java:288)
     at javax.mail.Service.connect(Service.java:169)
     at javax.mail.Service.connect(Service.java:118)
     at javax.mail.Transport.send0(Transport.java:188)
     at javax.mail.Transport.send(Transport.java:118)
     at MailClient.sendMail(MailClient.java:39)
     at MailClient.main(MailClient.java:76)
Caused by: java.net.ConnectException: Connection timed out: connect
     at java.net.PlainSocketImpl.socketConnect(Native Method)
     at java.net.PlainSocketImpl.doConnect(Unknown Source)
     at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
     at java.net.PlainSocketImpl.connect(Unknown Source)
     at java.net.SocksSocketImpl.connect(Unknown Source)
     at java.net.Socket.connect(Unknown Source)
     at java.net.Socket.connect(Unknown Source)
     at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
     at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
     ... 8 more
Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

I followed ur Advice
I got another code which works perfecty as i wanted
this uses Gmail SMTP
Thanks
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class Main
    String  d_email = "[email protected]",
            d_password = "password",
            d_host = "smtp.gmail.com",
            d_port  = "465",
            m_to = "[email protected]",
            m_subject = "Testing",
            m_text = "Hey, this is the testing email.";
    public Main()
        Properties props = new Properties();
        props.put("mail.smtp.user", d_email);
        props.put("mail.smtp.host", d_host);
        props.put("mail.smtp.port", d_port);
        props.put("mail.smtp.starttls.enable","true");
        props.put("mail.smtp.auth", "true");
        //props.put("mail.smtp.debug", "true");
        props.put("mail.smtp.socketFactory.port", d_port);
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.socketFactory.fallback", "false");
        SecurityManager security = System.getSecurityManager();
        try
            Authenticator auth = new SMTPAuthenticator();
            Session session = Session.getInstance(props, auth);
            //session.setDebug(true);
            MimeMessage msg = new MimeMessage(session);
            msg.setText(m_text);
            msg.setSubject(m_subject);
            msg.setFrom(new InternetAddress(d_email));
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
            Transport.send(msg);
        catch (Exception mex)
            mex.printStackTrace();
    public static void main(String[] args)
        Main blah = new Main();
    private class SMTPAuthenticator extends javax.mail.Authenticator
        public PasswordAuthentication getPasswordAuthentication()
            return new PasswordAuthentication(d_email, d_password);
}

Similar Messages

  • What/where is the "server address" for the My Cloud NAS?

    I recently purchased a 2TB My Cloud NAS to store my FLAC music files (many thousands of them). I'm trying to use JRiver as a media controller but I can't find a path to the files. I'm using a Macbook Air (osx 10.10.4). The controller program asks for a "server address" and I have no idea what it is or where I may find an address. The music files are in the Public folder and there is no other identiification for it as far as I know. One forum suggested the following link : http://wdc.custhelp.com/app/answers/detail/a_id/2686/~/how-to-map-a-wd-network-drive-on-a-mac This link offers several suggestions for a server address, but they are for My Book units and of course they don't work. Where, or how do I get a server address for my files on a My Cloud unit? I'm lost. I would appreciate any help. Thank you for your time.     Bill

    Welcome to the Community.
    In most cases, the Server Address is the current path that leads to the devices and/or shared folders. This means the IP address of your unit or your device name, and depending on your system, the exact location to the share with your data. You can obtain the current IP address used by your WD My Cloud in your router and also in your NAS's admin page.

  • What is my exchange server address?

    This is absolutely killing me. I successfully set up my exchange account on my iphone 3g before - but then i dropped it in water, had to get a new one and now i don't know how i set it up.
    i have owa access with https://server2.southeast.net/owa
    my username is shea
    i don't use a domain when i sign in, but in case it is southeast.
    i type in all my info, and when it asks for server, no matter what i type in always says exchange account verification failed.
    please help! btw, i'm using exchange 2007.

    Read this and post back if you have trouble.
    http://www.techsack.com/2008/08/19/getting-your-iphone-to-work-with-exchange-act ive-sync-ssl-certificate/

  • Mail Server "Type" and Mail Server "Address" for Incoming & Outgoing Mail

    First, the only browser I use is Mozilla's Firefox, the best browser hands down. Second, I have both a Yahoo email account and a Google "gmail" account that I use regularly (daily). I am trying to set up a mail washing program to rid myself of these ridiculous spammers & scammers, however I need to the the Incoming & Outgoing mail server "type" & "address" to do this and I seem to have guessed the yahoo settings, but I can't seem to get the Google gmail account set up properly. Yahoo settings that worked are: Server Type="POP3" and Server Address="pop.mail.yahoo.com", with advanced settings: Secure Authentication=Required, Secure Connection (SSL)=Required, Store Cached Emails=Yes, Server Port Number=995 (set), Pipelining=Enabled. The equivalent settings for the Google gmail account result in an error message = "Failed to log into POP3 Server". Of course user name & password triple checked, Type=POP3, Address=pop.mail.gmail.com, and , Address="pop.gmail.com" tried also, Port and other settings the same. Where can I find this info for both accounts? Tanks a million! -jw

    Yahoo and Gmail support should be able to help you.
    Not related to Firefox support, web mail doesn't use POP or SMTP protocols which is what email clients such as Thunderbird use for communicating with email servers.

  • Smtp and pop3 host and port name of gmail server?????

    can any body give me smtp and pop3 host and port name of gmail server?????to send a mail......

    Just do a new initial context and lookup the datasource, in case you need other info like host name and port you can use MBEans like:
              InitialContext ctx = null;
                   // fetch managed server name by accessing the
                   // RuntimeServerMBean using the
                   // MBeanServer interface
                   ctx = new InitialContext();
                   MBeanServer server = (MBeanServer) ctx
                             .lookup("java:comp/env/jmx/runtime");
                   ObjectName service = new ObjectName(
                             "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
                   managedServerName = (String) server.getAttribute(service,
                             "ServerName");

  • What is the real ip address to the apple server? Someone changed the host file in windows/system32/drivers/ect, and now I can't do a restore on my iPhone 3gs.

    What is the real ip address to the apple server? Someone changed the host file in windows/system32/drivers/ect, and now I can't do a restore on my iPhone 3gs

    "You have to change your router's IP address to be able to access it. It will not give you the internet."
    I'm not sure what that means Richard, but I did change the router's IP address from 192.168.1.1 to 192.168.5.1- isn't that what you meant in your first post. I know that isn't reflected in my screen capture that I took last night, but I did do that this morning after I read your post.
    "Log on to your router and change two settings.
    Change the setting in Setup from PPPoE to Automatic Configuration-DHCP and click on save.
    Click on Advance Routing and change the setting from Gateway to Router then click on save."
    I did this and still same results as far as I can tell. Can't get online through the router.
    "Click on MAC address clone under setup tab ... click enable & click clone ...click save settings ... Check the IPaddress under WAN page ....
    If getting IP in public range .... try going online ...."
    I tried this- at least to the part about checking the IP address under WAN. I assume you mean the WAN page in the modem setup- nothing looked any different after trying what you suggested, and I'm not really sure where I would be "getting IP in public range" or what that means.
    I'm about to give up and just buy a new router to see if I can get the same lack of results with a different one. My ISP maintains that everything is set up correctly on their end and really can't do anything more for me. The Modem works and is set up correctly and they can give tech support for a router.
    Here's what my basic setup looks like now:
    http://i490.photobucket.com/albums/rr270/SukarUDL/BasicSetup.png
    Here's what the advanced tab looks like now:
    http://i490.photobucket.com/albums/rr270/SukarUDL/AdvancedRouting.png
    Modem setup looks the same
    Message Edited by Writersbloc on 09-25-2008 07:05 PM

  • Java mail(fetch default SMTP server address)

    I am writting a code to send an email using Java Mail API.
    I have manged what I wanted(send a mail with an attachment)
    But in my code I have hard coded the SMTP server address,that is what I dont want to do .Is there anything in java which can fetch the default SMTP server address ?

    Let me send the code itself to make it clear
    Here the host is hard coded to10.1.1.5
    I dont want that ,rather I would like my code itself to fetch the host
    package javamail;
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class SendMailUsage {
    public static void main(String[] args) {
    // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
    String to = "[email protected]";
    String from = "[email protected]";
    // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
    String host = "10.1.1.5";
    // Create properties for the Session
    Properties props = new Properties();
    // If using static Transport.send(),
    // need to specify the mail server here
    props.put("mail.smtp.host", host);
    // To see what is going on behind the scene
    props.put("mail.debug", "true");
    // Get a session
    Session session = Session.getInstance(props);
    try {
    // Get a Transport object to send e-mail
    Transport bus = session.getTransport("smtp");
    // Connect only once here
    // Transport.send() disconnects after each send
    // Usually, no username and password is required for SMTP
    bus.connect();
    //bus.connect("smtpserver.yourisp.net", "username", "password");
    // Instantiate a message
    Message msg = new MimeMessage(session);
    // Set message attributes
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address = {new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    // Parse a comma-separated list of email addresses. Be strict.
    msg.setRecipients(Message.RecipientType.CC,
    InternetAddress.parse(to, true));
    // Parse comma/space-separated list. Cut some slack.
    msg.setRecipients(Message.RecipientType.BCC,
    InternetAddress.parse(to, false));
    msg.setSubject("Test E-Mail through Java");
    msg.setSentDate(new Date());
    // Set message content and send
    setTextContent(msg);
    msg.saveChanges();
    bus.sendMessage(msg, address);
    setMultipartContent(msg);
    msg.saveChanges();
    bus.sendMessage(msg, address);
    setFileAsAttachment(msg, "D:/ketan.txt");
    msg.saveChanges();
    bus.sendMessage(msg, address);
    setHTMLContent(msg);
    msg.saveChanges();
    bus.sendMessage(msg, address);
    bus.close();
    catch (MessagingException mex) {
    // Prints all nested (chained) exceptions as well
    mex.printStackTrace();
    // How to access nested exceptions
    while (mex.getNextException() != null) {
    // Get next exception in chain
    Exception ex = mex.getNextException();
    ex.printStackTrace();
    if (!(ex instanceof MessagingException)) break;
    else mex = (MessagingException)ex;
    // A simple, single-part text/plain e-mail.
    public static void setTextContent(Message msg) throws MessagingException {
    // Set message content
    String mytxt = "This is a test of sending a " +
    "plain text e-mail through Java.\n" +
    "Here is line 2.";
    msg.setText(mytxt);
    // Alternate form
    msg.setContent(mytxt, "text/plain");
    // A simple multipart/mixed e-mail. Both body parts are text/plain.
    public static void setMultipartContent(Message msg) throws MessagingException {
    // Create and fill first part
    MimeBodyPart p1 = new MimeBodyPart();
    p1.setText("This is part one of a test multipart e-mail.");
    // Create and fill second part
    MimeBodyPart p2 = new MimeBodyPart();
    // Here is how to set a charset on textual content
    p2.setText("This is the second part", "us-ascii");
    // Create the Multipart. Add BodyParts to it.
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(p1);
    mp.addBodyPart(p2);
    // Set Multipart as the message's content
    msg.setContent(mp);
    // Set a file as an attachment. Uses JAF FileDataSource.
    public static void setFileAsAttachment(Message msg, String filename)
    throws MessagingException {
    // Create and fill first part
    MimeBodyPart p1 = new MimeBodyPart();
    p1.setText("This is part one of a test multipart e-mail." +
    "The second part is file as an attachment");
    // Create second part
    MimeBodyPart p2 = new MimeBodyPart();
    // Put a file in the second part
    FileDataSource fds = new FileDataSource(filename);
    p2.setDataHandler(new DataHandler(fds));
    p2.setFileName(fds.getName());
    // Create the Multipart. Add BodyParts to it.
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(p1);
    mp.addBodyPart(p2);
    // Set Multipart as the message's content
    msg.setContent(mp);
    // Set a single part html content.
    // Sending data of any type is similar.
    public static void setHTMLContent(Message msg) throws MessagingException {
    String html = "<html><head><title>" +
    msg.getSubject() +
    "</title></head><body><h1>" +
    msg.getSubject() +
    "</h1><p>This is a test of sending an HTML e-mail" +
    " through Java.</body></html>";
    // HTMLDataSource is an inner class
    msg.setDataHandler(new DataHandler(new HTMLDataSource(html)));
    * Inner class to act as a JAF datasource to send HTML e-mail content
    static class HTMLDataSource implements DataSource {
    private String html;
    public HTMLDataSource(String htmlString) {
    html = htmlString;
    // Return html string in an InputStream.
    // A new stream must be returned each time.
    public InputStream getInputStream() throws IOException {
    if (html == null) throw new IOException("Null HTML");
    return new ByteArrayInputStream(html.getBytes());
    public OutputStream getOutputStream() throws IOException {
    throw new IOException("This DataHandler cannot write HTML");
    public String getContentType() {
    return "text/html";
    public String getName() {
    return "JAF text/html dataSource to send e-mail only";
    } //End of class

  • What impact is there on ODSEE (11.1.1.3) if host IP address changes?

    We are upgrading hardware and DS software.
    First we install ODSEE on a new host. Then we migrate the Directory schema and data from iPlanet 5.1 to ODSEE 11.1.1.3 on the new host.
    What we would like to do next is to change the ODSEE host's IP number back to the original iPlanet's host's IP address.
    What problems are there in ODSEE if/when host IP address changes?

    As long as the directory server is able to use a constant host name and FQDN, it should not matter that the IP address for that host changes. You are well advised to test before doing it in production but I do not consider this to be a problem.

  • What is the smtp incoming mail server for iCloud?

    What is the smtp incoming mail server for iCloud?

    There is no such thing as an "SMTP incoming mail server." You set up iCloud mail by checking the box marked Mail in the iCloud preference pane. You don't need to know the addresses of the servers.

  • IMAC: What is the SMTP outgoing mail server?

    IMAC: What is the SMTP outgoing mail server?

    You need to get that information from your internet service provider if you are using an email address provided by them or, if you are only using iCloud, then the info can be found here:
    http://support.apple.com/kb/HT4864
    FWIW, in order to set up email, you need both an incoming and outgoing server address (in addition to your email address/user name and password). Those are the servers your email program uses when sending or receiving emails.

  • Email shows my host server name not my email address?

    Golive user, using ProcessForm3 from mindpalette. Need to know what line to add/ an email so my server address won't show up in the recipients "from" box when they receive the contact/web submission form I have added to my clients websites. If someone is interested in helping me, I will attach source code for you to review.
    Also, need to know where to add additional attachment size code to my php.ini file.
    Thank you for your help in advance.

    I'm not familiar with the mindpalette script but somewhere in there should be a variable you might set. Search it for 'send' or 'sender'.
    There are a few places in PHP.ini to set attachment size as such an operation may affect both the size of the attachment and the RAM needed to process it. PHP.ini should be commented as well for this. You may wish to contact your web host for assistance as they might limit resources to you that will override what you set in php.ini.

  • I'm tring to allow a pop up so I can change my address on my drivers license. everytime I enter the address for the document , I get."what is the host name?" I'm clueless as to the host name

    I am trying to disable my pop up's in order to allow an address so I can change the address on my drivers license. When I enter the address that allows the document that I need to appear, I get, "what is the host name? I don't know what they mean by host name.

  • Whats code to get x400 address on exchage server 2007

    whats code to get x400 address on exchage server 2007

    Hi,
    Do you want to get a list of X400 address in Exchange 2007?
    You can use the following scripts to check result.
    $Recipients = Get-Mailbox -ResultSize Unlimited | Where {$_.EmailAddresses -like "X400.*"}
    foreach ($Recipient in $Recipients)
    Get-mailbox –Identity $Recipient.Identity –ResultSize Unlimited | select EmailAddresses
    If you want to check how many users have an X.400 address, you can use the scripts below to check result.
    ForEach ($address in (Get-Mailbox -ResultSize Unlimited | Select EmailAddresses) ){$address.EmailAddresses | Where {$_.Prefix -match"X400"} | Select AddressString}
    Best regards,
    Belinda Ma
    TechNet Community Support

  • Whats my name server address

    keep unexplained lingo to a minimum for the novice webber
    i don't know what a url is
    i just want to tell my domain registering company (awesomenet) my name server address for my iweb site so i can use my pre-existng domain name to send inquiries to this iweb site
    thanks
    mike

    Question 1: Do you have a .Mac account?
    If you do your url (web address) for your iweb site will be http://web.mac.com/your.username
    It is possible for you to use url forwarding so that when people enter the address of your already existing website, they automatically get forwarded to your iweb address. However, the iweb address will show up in the address field, which means that if people want to bookmark your page, they will end up bookmarking the iWeb page as opposed to your original predefined address.

  • TS3899 what is the outgoing server port for smtp

    what is the outgoing server port for smtp

    Google is your friend for searching for SMTP configuration for your Email provider
    25 is blocked by most providers (because of spam)
    465 and 587 are the ports used by authenticated SMTP setups.

Maybe you are looking for