title: Error: EmailException (Java): Sending the email to the following server failed : 127.0.0.1:3838
body: <p>I'm trying to send a mail with the following code but I'm getting the error as in below:
  Can anyone please tell me how to overcome this error?</p>
  
  <p>Is it because of the server I have connected to or is there some other reason for this error?   </p>
  
  <pre><code>     &gt; library(sendmailR)
         library(mailR)
         send.mail(from = "x@company.com",
                    to = c("y@company.com"),
                    #cc = c("CC Recipient &lt;cc.recipient@gmail.com&gt;"),
                    #bcc = c("BCC Recipient &lt;bcc.recipient@gmail.com&gt;"),
                    subject = "Subject of the email",
                    body = "Body of the email",
                    smtp = list(host.name = "127.0.0.1", port = 3838),
                    authenticate = FALSE,
                    send = TRUE)
  </code></pre>
  
  <p>When I run the above code I get following output with error:</p>
  
  <pre><code>        org.apache.commons.mail.EmailException: Sending the email to the following server failed : 127.0.0.1:3838
              at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
              at org.apache.commons.mail.Email.send(Email.java:1437)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at RJavaTools.invokeMethod(RJavaTools.java:386)
          Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: 127.0.0.1, 3838; timeout 60000;
            nested exception is:
              java.net.ConnectException: Connection refused: connect
              at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2053)
              at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
              at javax.mail.Service.connect(Service.java:364)
              at javax.mail.Service.connect(Service.java:245)
              at javax.mail.Service.connect(Service.java:194)
              at javax.mail.Transport.send0(Transport.java:253)
              at javax.mail.Transport.send(Transport.java:124)
              at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
              ... 6 more
          Caused by: java.net.ConnectException: Connection refused: connect
              at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
              at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
              at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
              at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
              at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
              at java.net.PlainSocketImpl.connect(Unknown Source)
              at java.net.SocksSocketImpl.connect(Unknown Source)
              at java.net.Socket.connect(Unknown Source)
              at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:310)
              at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)
              at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
              ... 13 more
          NULL
  
          **Error: EmailException (Java): Sending the email to the following server failed : 127.0.0.1:3838**
  </code></pre>