Specifying SMTP port with JavaMail

Hi,
I am trying to specify a non-default port for SMTP server when using JavaMail, but JavaMail seems to ignore my settings for the specific port. Regardless of my port setting, it seems to always use port 25 to connect to the SMTP server.
I am using JavaMail 1.4ea and I specify the SMTP port as following:
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", mailhost);
props.put("mail.smtp.port", smtpPort);
Regardless of what the smtpPort is above, JavaMail always connects to port 25 as shown in the debug output below:
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "test.server.com", port 25, isSSL false
Has anyone seen this behavior ? Is there a different way to specify an alternative port for the SMTP server ?
Thanks.

Thanks for your suggestion. You were right on the mark.
The problem with my code was that smtpPort was int, and autoboxing made it Integer and added to the props without any compile time problems. But props.getProperty("mail.smtp.port") returns null unless the value is String. That caused JavaMail to use the default port.
props.setProperty(String key, String value) would have been a safer
way to set this.
Thanks again.

Similar Messages

  • Problem sending emails on SMTP Port 25 with Z10

    Hi Blackberry,
    Its very disappointing that new Z10 cannot configure my business email. I can receive the email but cannot reply or send emails. There is a serious issues with the SMTP Ports with this device. Blackberry should resolve this issue earliest or die hard fans of blackberry like me shall be done with it. Z10 does not configure on SMTP Port 25. Please resolve this issue asap.

    Port 25 is blocked on most ISPs now. you need a SSL type of connection to make it work everywhere.
    this is not a BlackBerry problem really, the world of email has changed and port 25 should never be used by any mobile client
    what mail server is this using? maybe you can configure a new port or even use IMAP or EAS which is much better for mobile use
    Click here to Backup the data on your BlackBerry Device! It's important, and FREE!
    Click "Accept as Solution" if your problem is solved. To give thanks, click thumbs up
    Click to search the Knowledge Base at BTSC and click to Read The Fabulous Manuals
    BESAdmin's, please make a signature with your BES environment info.
    SIM Free BlackBerry Unlocking FAQ
    Follow me on Twitter @knottyrope
    Want to thank me? Buy my KnottyRope App here
    BES 12 and BES 5.0.4 with Exchange 2010 and SQL 2012 Hyper V

  • How to specify an SMTP port rather than 25 in JavaMail?

    This is my segment of code, but I don't know where I can specify the SMTP port. Please help me.
    Properties props = System.getProperties();
    props.put("mail.smtp.host", "smtp.mail.yahoo.com");
    Session session = Session.getDefaultInstance(props,
        new MyAuthenticator("dxxvi", "nopassword"));
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress("[email protected]",
                                        "Thai Dang Vu"));
    message.addRecipient(Message.RecipientType.TO,
        new InternetAddress("[email protected]"));
    message.setSubject("I test the Yahoo! Mail Plus service");
    message.setSentDate(new Date());
    Multipart multipart = new MimeMultipart();
    BodyPart bodyPart = new MimeBodyPart();
    bodyPart.setText("If you can read this, $19.99/year is worthy");
    multipart.addBodyPart(bodyPart);
    bodyPart = new MimeBodyPart();
    bodyPart.setDataHandler(
        new DataHandler(new FileDataSource("Resume.doc")));
    bodyPart.setFileName("Resume.doc");
    multipart.addBodyPart(bodyPart);
    message.setContent(multipart);
    Transport.send(message);

    props.put("mail.smtp.port", "42");

  • Specified SMTP server name is replaced with localhost

    Hi,
    I am getting following error when I try to send email from a
    java program. The same program works on development server but
    gives following exeception on production. Somehow it is replacing
    the specified SMPT server with localhost while making the
    connection
    javax.mail.MessagingException: Could not connect to SMTP
    host: localhost, port: 25; nested exception is:
    java.net.ConnectException: Connection refused:
    Please let me know the cause.
    Thanks
    Mahesh

    Do you really have a SMTP server installed on your local machine?
    If it does, you should set "mail.smtp.host" as "localhost".
    props.put("mail.smtp.host", "localhost");
    javax.mail.Session mail_session = javax.mail.Session.getInstance(props, null);

  • Error 550 5.7.1 unable to relay with SMTP PORT 25 Exchange 2013

    Hi All,
    I know this issue has been posted for a while, but still can't resolved issue. We've new Exchange 2013 SP1 (CU4) installation, everything is working properly, the OWA, Exchange Client Connection, SMTP/POP with SSL, except with SMTP Using Port 25 Non-Encrypted
    Connection.  
    If I'm using the SMTP Port 25 without TICK "My Outgoing Server (SMTP) Requires authentication", I've got the error: "550 5.7.1 Unable to relay", but if I TICK the option above, my message will be deliver without any error, how do i get
    rid this problem, I need to UN-TICK the option above for the time being, since we've hundreds email account, I want to avoid to educate and tell the user and even remote their PC, just to configure this issue, it will drive me crazy, we're going to use the
    Exchange Client Connection in the future, If everything is smooth and ok.
    I research this problem on the Internet and of course with TECHNET, but still can't, anyone can help me on this?
    fyi, I tried so many things, delete the default the Default Front End Transport for Port 25, it also not fix my issue.
    Thx
    Irwan

    Hi
    You can paste the output of below result
    Get-receiveconnector | fl name,bindings,PermissionGroups
    I think your default receive connector should be missing out some permissions.
    Also try to see if you get any message on protocol logs and paste them too
    Remember to mark as helpful if you find my contribution useful or as an answer if it does answer your question.That will encourage me - and others - to take time out to help you Check out my latest blog posts on http://exchangequery.com Thanks Sathish
    (MVP)

  • Sending email using IMAP through SMTP Port 587

    Hi,
    I have been sending Mail Merged email to people in organizations that I am active in, using IMAP embedded in StarOffice 5.2 (on Windows 98 Second Edition). This worked fine until a few weeks ago when I received an error message stating that AOL, as part of their anti-spam efforts, was no longer accepting third-party emails on default port 25. All third-party email must now use port 587. I looked in the IMAP dialog and in the Tools -> Options dialog, but did not see any place to change the SMTP port. The AOL error message information page had instructions for changing the port in other applications (Outlook, Eudora, etc.), but not for StarOffice. So, I have some questions:
    1.Is it possible to change the port in StarOffice 5.2?
    2.If not, how does StarOffice 8 send Mail Merged email? Does it use IMAP, and if so, can the port be changed?
    3.Also, I like the integrated configuration in StarOffice 5.2, where database fields can be directly accessed in the Insert -> Fields -> Other dialog. In looking at the Mail Merge section in "SO8_What's New.pdf", it appears that Mail Merge in StarOffice 8 is restricted to predefined fields. Could I still access fields from my existing databases?
    These is a lot of questions, but right now I am blocked from sending Mail Merged emails which is imparing communications with volunteers who are running educational programs. I appreciate any and all help that anyone can provide.

    Please try this out!!!!!!!!!
    You can send emails using Outlook also. You can send email over Microsoft Exchange with this object (or another email server, using IMAP/POP).
    Sub SendMailOutlook(aTo, Subject, TextBody, aFrom)
    'Create an Outlook object
    Dim Outlook 'As New Outlook.Application
    Set Outlook = CreateObject("Outlook.Application")
    'Create e new message
    Dim Message 'As Outlook.MailItem
    Set Message = Outlook.CreateItem(olMailItem)
    With Message
    'You can display the message To debug And see state
    '.Display
    .Subject = Subject
    .Body = TextBody
    'Set destination email address
    .Recipients.Add (aTo)
    'Set sender address If specified.
    Const olOriginator = 0
    If Len(aFrom) > 0 Then .Recipients.Add(aFrom).Type = olOriginator
    'Send the message
    .Send
    End With
    End Sub

  • Sending email with javamail

    Hi
    I am new to javaMail....And i having a problem with this program.
    I getting the following exception when the run the following program
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.Properties;
    public class MailDemo
    public static void main(String[] args) throws Exception
    boolean debug = false;
    //Set the host smtp address
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.mail.yahoo.com");
    props.put("mail.transport.protocol","smtp");
    props.put("mail.smtp.port","25");
    // create some properties and get the default Session
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(debug);
    // create a message
    Message msg = new MimeMessage(session);
    Transport transport = session.getTransport();
    // set the from and to address
    InternetAddress addressFrom = new InternetAddress("[email protected]");
    msg.setFrom(addressFrom);
    InternetAddress addressTo = new InternetAddress("[email protected]");
    msg.setRecipient(Message.RecipientType.TO, addressTo);
    // Optional : You can also set your custom headers in the Email if you Want
    msg.addHeader("MyHeaderName", "myHeaderValue");
    // Setting the Subject and Content Type
    //msg.setSubject(subject);
    //msg.setContent(message, "text/plain");
    //Transport.send(msg);
    msg.setSubject("Testing javamail plain");
    msg.setContent("This is a test", "text/plain");
    transport.sendMessage(msg,msg.getRecipients(Message.RecipientType.TO));
    transport.close();
    I get th following error message:
    Exception in thread "main" java.lang.IllegalStateException: Not connected
    at com.sun.mail.smtp.SMTPTransport.checkConnected(SMTPTransport.java:151
    1)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:548)
    at MailDemo.main(MailDemo.java:51)
    It is a simple program to send a plain email...
    Can anyone help me out
    Thanks in advance
    Deepthi

    It's not connected because you never call Transport.connect.
    It's not clear from your code why you chose to use the more
    complex way of managing the Transport object yourself rather
    than just using the static Transport.send method.
    You're also setting some properties that don't really need to be
    set because they match the default values.

  • How to use gmail with JavaMail

    JavaMail 1.4 is capable of sending and reading messages using gmail.
    All that's required is to properly configure JavaMail. I'll
    illustrate the proper configuration using the demo programs that
    come with JavaMail - msgshow.java and smtpsend.java.
    Let's assume your gmail username is "[email protected]" and your
    password is "passwd".
    To read mail from your gmail Inbox, invoke msgshow as follows:
    java msgshow -D -T pop3s -H pop.gmail.com -U user -P passwdBy reading the msgshow.java source code, you can see how these
    command line arguments are used in the JavaMail API. You should
    first try using msgshow as shown above, and once that's working
    move on to writing and configuring your own program to use gmail.
    To send a message through gmail, invoke smtpsend as follows:
    java -Dmail.smtp.port=587 -Dmail.smtp.starttls.enable=true smtpsend
            -d -M smtp.gmail.com -U user -P passwd -A [email protected](Note that I split the command over two lines for display, but you
    should type it on one line.)
    The smtpsend command will prompt for a subject and message body text.
    End the message body with ^D on UNIX or ^Z on Windows.
    Gmail requires the use of the STARTTLS command, and requires a
    non-standard port, which the smtpsend program doesn't have command
    line options to select so we set them as System properties on the
    java command. The smtpsend.java program uses the System properties
    when creating the JavaMail Session, so the properties set on the
    command line will be available to the JavaMail Session.
    Again, you can read the smtpsend.java source code to see how the
    command line arguments are used in the JavaMail API. There is,
    of course, more than one way to use the JavaMail API to accomplish
    the same goal. This should help you understand the essential
    configuration parameters necessary to use gmail.
    And no, I won't send you an invitation to gmail. Sorry.

    I notice that it's possible to have sticky posts in these forums. See
    http://forum.java.sun.com/forum.jspa?forumID=534
    the Concurrency forum for an example. Posting a link to the FAQ in a sticky post might reduce the number of FAQs asked here by maybe 1%? Or posts like this one might do well as a sticky?

  • Alert emails to a non standard SMTP port

    Is it possible to configure LiveCycle ES 8.2 to send its alert emails to an SMTP server on a non standard port?  In the AdminUI there is a field for the server but not for the port.
    Thanks,

    Hi Jon
    Sorry, I thought we were talking about Task Notifications not Administrator Notifications.
    Changing the port in the Email Notifications process will work for Task Notifications.
    Administrator Notifications use the Java mail default, which is port 25 unless otherwise specified on your system.
    Are you using the JBoss Turnkey?
    if so, you can try this:
    1. Navigate to C:\Adobe\LiveCycle8.2\jboss\server\all\deploy
    2. Locate the properties-service.xml file.
    3. uncomment the following block and set the property as follows:
        <!--
           | Set raw properties file style properties. -->
        <attribute name="Properties">   
              smtp.mail.port =<your port #>
        </attribute>
    4. You don't need to restart JBoss.
    The only downside is that this is now the smtp port for that server and any other apps on that server.
    If you can live with that, it's an easy workaround.
    Diana

  • RV042 Router SMTP port change

    Hello, I have an RV042 that I have configured to send alert logs to a comcast email address. Recently comcast changed their SMTP port from 25 to 465. I can't find where to change the port settings in the RV042 to send the router logs via port 465. Any help would be appreciated.
    Thanks
    Mark               

    Hi Mark, thanks for using our forum, my name is Johnnatan and I am part of the Small business Support community. You can change the port number using a port-forwarding or a One-to-One NAT in your device, you can also specify the syslog server, I´ll share with you some documentation about it:
    http://www6.nohold.net/CiscoSB/Loginr.aspx?login=1&pid=2&app=search&vw=1&articleid=544
    http://www6.nohold.net/CiscoSB/Loginr.aspx?login=1&pid=2&app=search&vw=1&articleid=346
    I hope you find this answer useful,
    **Please rate useful posts so other users can benefit from it**
    Greetings,
    Johnnatan Rodriguez Miranda.
    Cisco Network Support Engineer.

  • Mail relay server specifying a port...

    Hi,
    The advanced server guide says you should be anle to specify a port .. ie.. myserver:587  in the dialog box.
    Dialog box says Formatting error invalid value.
    I use the Dyn mailforwarding service .. or i did till the latest upgrade broke it.
    Does anyone know of a fix? .. I assume it will mean editing the postfix files .. that no doubt the next upgrade will break again.
    Thanks in advance.

    You have to edit the configuration using the command line; Server.app lost the ability to handle the outbound SMTP relay otherwise.
    sudo serveradmin settings mail
    You're after the relayhost setting (the following is from a generic setup, you'll want to set the host name via the GUI then check the output here, and add the port to the relayhost specification:
    $ sudo serveradmin settings mail | grep -i relay
    mail:postfix:smtp_auth_relay_dict:smtp_auth_relay_userid = ""
    mail:postfix:smtp_auth_relay_dict:smtp_auth_relay_pwd = ""
    mail:postfix:smtp_auth_relay_dict:smtp_auth_relay_host = ""
    mail:postfix:luser_relay_enabled = no
    mail:postfix:relayhost = ""
    mail:postfix:relayhost_enabled = no
    mail:imap:lmtp_luser_relay_enabled = no
    mail:imap:lmtp_luser_relay = ""
    $
    Once edited, you'll end up with something like this:
    mail:postfix:relayhost = "mail.example.com:587"
    Where you've entered your relay host and port.   See this thread (for the Postfix-level path to this data and for some background, I'd generally use serveradmin here and not the Postfix-level access) and see this Krypted article for some more details on the setup and commands available here.
    You can use  postconf -n /Library/Server/Mail/Config/postfix to verify that the changes have been implemented, and here's a similar discussion of the lower-level path into this same general area.

  • How can I see / change the smtp ports in use by FF 12.0 on my WIN2K antique?

    My webmail account works, though slowly, when I'm using NetScape 7.1. When I try to use the same program and service with FireFox 12.0, I can receive email, but sending email gets me an error message that's something like "Could not establish an SMTP commection with the server." The service tells me that my outgoing smtp port should be 465 if I'm using SSL, and 25 if I'm not using SSL. Also, if I'm asked about "authentication," it should be "the same as incoming." Where do I find these settings in FF12.0?
    I'm asking this question on another computer, not the one I'm having trouble with. My problem child is an IBM Aptiva running Windows 2000 Version 5.0 (Build 2195; Service Pack 4) Copyright 1981-1999 Microsoft Corp. Physical memory available to Windows: 64,824 KB

    Gingerbread_Man, you were right on the nose with the answer to the problem. After I installed Simple Mail v. 2.83.2, my webmail began to work with Firefox v. 12.0. My s-l-o-w computer is now a bit faster, as well, though I don't know how that could have had any connection with Simple Mail. Oh, Telga, TechnalXS, the developer, changed versions to 2.84 while I was installing 2.83.2, so I started over and finished up with the new one. What had me going was that every time I tried to print a copy of their web site, Firefox crashed and burned. Had to be that document, because other things print just fine. Anyway, thanks for your help. I'm going to recommend that Santa put you on his "good list!"

  • SMTP Port # for use in hotels etc

    Ive tried various methods and have webmail enabled but wondering if there is a recommended alternate port user's can input into entourage/mail when in a hotel or something where 25 is blocked. What's a recommended way to change it or add it on there Xserve? (10.4.x)
    Currently I used a relay on another port but want to get rid of that.
    Thanks

    Your client can use ANY port the server is configured to use.
    By default, OS X Server mail only accepts smtp on port 25.
    If you are using OS X Server as your SMTP, you can enable other ports (any unused port like 2525, 5000, 587, 5555 etc etc etc) by modifying master.cf
    If you want to enable another port with the same options as port 25, find this line:
    smtp inet n - n - - smtpd
    Add another below it
    587 inet n - n - - smtpd
    Above will enable port 587.
    Be sure to map the port in your router.
    Then issue:
    suso postfix reload
    You can test a connection by issuing:
    telnet mail.domain.com 587
    If you receive a postfix greeting, it worked.
    You can use master.cf to control what is allowed on each port.
    On my server, I have port 587 set to ONLY accept mail with SMTP Authentication, not even for local delivery.
    Port 25 is configured to ONLY accept mail for local delivery, and never allows relay, not even with SMTP Authentication.
    Jeff

  • How to send a message with javamail api

    Hi, anybody can tell me how i do to send a message with javamail?
    Thanks.
    Daniele.

    [rossifumi80],
    Here's a simple JavaMail application SendMessage.java that will connect a SMTP host and send a mail message out:
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class SendMessage {
      public static void main (String args[]) throws Exception {
        String host = args[0];
        String from = args[1];
        String to = args[2];
        // Get system properties
        Properties props = System.getProperties();
        // Setup mail server
        props.put("mail.smtp.host", host);
        // Get session
        Session session = Session.getDefaultInstance(props, null);
        // Define message
        MimeMessage message = new MimeMessage(session);
        // Set the from address
        message.setFrom(new InternetAddress(from));
        // Set the to address
        message.addRecipient(Message.RecipientType.TO,
          new InternetAddress(to));
        // Set the subject
        message.setSubject("Hello JavaMail");
        // Set the content
        message.setText("Welcome to JavaMail");
        // Send message
        Transport.send(message);
    }HTH.
    Allen Lai
    Developer Technical Support
    SUN Microsystems
    http://www.sun.com/developers/support/

  • Sending � signs with JavaMail

    Hi chaps,
    At our company we use the JavaMail API through JNI to send emails externally to customers.
    Recently the business has decided that it would be nice to send pound (�) through, however it's not going to plan.
    Normally the messages are encoded in 7-bit which would seem to exclude the � (163), however it seems that it is first converted to a (=80, hex with no ascii correlation) and then to a Euro symbol.
    I've tried setting the "allow8bitmime" property in order to enable the SMTP service to support 8-bit encoding, but it's not working AND Microsoft say that our Exchange (v5.5) doesn't support 8-bit MIME types. The odd thing is that sending external emails via Exchange supports the � with no problems and is read in the mail reader as 8-bit encoded (!).
    Has anybody had any experience with issues like this ? Any reply appreciated.
    Thanks
    Ammonite

    Ammonite,
    I am working on a similar problem.. Did you say your
    email gets translated and prints the Euro symbol... I
    actually need out email to print Both the pound and
    the Euro and it does niether right now.. The current implementation I am working on will display a Euro instead of a pound, although this isn't by design. The message is encoded using "Quoted-Printable" and substitutes the pound for a =80 character. How this maps to a Euro is unknown to me :(
    In standard ascii the pound is outside the standard 7-bit encoding range (163) and featured in the Extended Set on the platform we use. I'm not sure about the Euro. The Iso-8859-1 charset which SH provided supports the pound in "Quoted-Printable" encoding, but this hasn't been well received by JavaMail MIME objects that I have tried.
    I haven't managed any sort of 8-bit encoding with JavaMail as yet, due to supposed lack of support in Exchange 5.5 and lack of response to the "allow8bitmime" property.
    does anyone know is using MimeMessage limit the
    message to ASCII characters only and does that rule
    out the Euro and the Pound symbol/
    It shoudn't rule them out, but I'm starting to believe that MimeMessages are necessarily helping things here :)

Maybe you are looking for

  • System went down after this message Client is not known to the mess server

    Hi Guru's, I am running 4.6c on Ora 8i, Windows 2000 Server. We have 1 application server. The central instance and DB is on same host. <b>Initially i got following error message 2 times in the system log reading:-</b> No free memory available in cla

  • Material allocation for a customer with a SO

    Hi, Is it possible to allocate a stock against a customer even though the SO is not available in the system. If yes then how this is possible in APO? regards, Mohit

  • Error in portal content

    Hi experts!! Just yesterday our basis person finished the EP installation. I tried to access the portal content to start designing iviews etc.. but under the tab "browse" in the portal content nothing was there. Since this is my first portal project

  • Set up new BSP project

    Hello experts. Want to you suggest me best solution of my task. Requirements of an app (mobile) are following : 1. when user opens app on device - He sees some data from SAP on UI, but He does not need to login (some hardcoded user need to be used he

  • Laptop WILL NOT turn on no matter what I try.

    Hi! Listen, I have tried everything. My laptop was working excellent last night, but as soon as I get up and come back, it won't even turn on. My AC adapter is still charging it as the Orange light/White light is still on. I try to boot it up but the