Sending mail with username and pasword.

Lets say that I wanted to write some code which can send messages via my gmail account. How could I tell my session that what my username and password are?

Can't get this code to work. Can't get past the Transport.send(msg) part but it doesnt throw an exception instead it just blocks indefinitely.
package mailtest;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class Main
    public static void main(String[] args) throws Throwable
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "465");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.user", "[email protected]");
        props.put("mail.smtp.password", "*********");
        Session s = Session.getDefaultInstance(props, new javax.mail.Authenticator()
            public PasswordAuthentication getPasswordAuthentication()
                return new PasswordAuthentication("[email protected]", "*********"); // password not displayed here, but gave the right password in my actual code.
        MimeMessage msg = new MimeMessage(s);
        msg.setFrom(new InternetAddress("[email protected]"));
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
        msg.setSubject("NONE");
        msg.setText("Hello!");
        Transport.send(msg);
        System.out.println("SENT");
}

Similar Messages

  • Send mail with attachment and more recipients

    Hi to all,
    I have this procedure :
    PROCEDURE SPEDISCI_MAIL
    Mittente IN VARCHAR2,
    Destinatario IN VARCHAR2,
    Oggetto IN VARCHAR2,
    Messaggio IN VARCHAR2
    IS
    mailhost VARCHAR2(40) := 'pippo.com';
    conn utl_smtp.connection;
    crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 );
    mesg VARCHAR2( 1000 );
    local_mittente VARCHAR2(2000) := mittente;
    BEGIN
    conn := utl_smtp.open_connection (mailhost,25);
    mesg:='Date:'||TO_CHAR(SYSDATE,'dd mon yy hh24:mi:ss')||crlf||
    'From:<'||mittente||'>'||crlf||
    'Subject:'||Oggetto||crlf||
    'To:'||destinatario||crlf||''
    ||crlf||messaggio;
    utl_smtp.helo(conn, mailhost);
    utl_smtp.mail(conn,local_mittente);
    utl_smtp.rcpt(conn,destinatario);
    utl_smtp.data(conn, mesg);
    utl_smtp.quit(conn);
    END;
    Can I send mail with attachment and more recipients?
    Thank you
    Silvia

    Consider using UTL_MAIL package:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_mail.htm
    (Note: it's not installed and configured by default, but the scripts are supplied with the Oracle database, see documentation for instructions)

  • Sending Mail with attachment and preserving the order of attachment

    Hi Everyone!!!!!!
    My requirement is to send Email with attachment in the same order as they were attached by Sender while composing the mail. I want to preserve order of attachment in the mail and when receiver open a mail, the attached files should be reflected in same order as it was on sender side. In my application,the documents being upload are already in my database. So, user just requires to mark the corresponding check box and enter the Sequence number for each attachment. When he clicks on "SEND" button, the Source file is first written from database to OS level and then files are attached from source available on OS . The attached file name could be anything. Based on the Sequence number file should be attached and send. My current code works fine,but problem it is that the Sequence number is not preserved in my attachment . However, when I traced the output of FOR Loop by inserting it in a table " temp_trace" I found that the Sequence is preserved in the order that I want. So, I think that uploaded files are written on the Operating system in same order but they are not attached in same order. Below is the sample code that is I am using to attach file in email. Here, the user_sequence is the sequence number entered by user.
    for i in (select case when user_sequence is not null
    then trim(to_char(user_sequence ,'09'))||'_'||file_name||'.pdf'
    else ||'_'||file_name||'.pdf' end file_name ,
    file_src,length(file_src) len,cd.doc_id,PRIORITY from
    MIM_CLIENT_DOCS CD,(select DOC_ID ,user_sequence from table P_DOC_AND_user_sequence ) TEMP_TAB
    WHERE CD.DOC_ID = TEMP_TAB.DOC_ID order by case when user_sequence is null then 1 else 0 end, file_name)
    loop
    insert into temp_trace values(i.file_name);
    L_OUT := UTL_FILE.FOPEN(v_oracle_dir,i.file_name,'wb',32760);
    end loop;
    I want my output as
    1_first attachment.txt
    2_second_attachment.docx
    3_abc.sql
    _xxx.txt  ------------------ When sequence is not assigned by user That is null at last.
    Unfortunately, I am not getting attachment in mail in this sequence. Can anyone give me suggestion.
    Sorry for stuff essay and thanks in advance!!!!!!!!!!!

    >
    Please update your forum profile with a real handle instead of "974850".
    My requirement is to send Email with attachment in the same order as they were attached by Sender while composing the mail. I want to preserve order of attachment in the mail and when receiver open a mail, the attached files should be reflected in same order as it was on sender side. In my application,the documents being upload are already in my database. So, user just requires to mark the corresponding check box and enter the Sequence number for each attachment. When he clicks on "SEND" button, the Source file is first written from database to OS level and then files are attached from source available on OS . The attached file name could be anything. Based on the Sequence number file should be attached and send. My current code works fine,but problem it is that the Sequence number is not preserved in my attachment . However, when I traced the output of FOR Loop by inserting it in a table " temp_trace" I found that the Sequence is preserved in the order that I want. So, I think that uploaded files are written on the Operating system in same order but they are not attached in same order. Below is the sample code that is I am using to attach file in email. Here, the user_sequence is the sequence number entered by user.Always post code using <tt>\...\</tt> tags as described in the FAQ.
    for i in (select case when  user_sequence is not null
    then trim(to_char(user_sequence ,'09'))||'_'||file_name||'.pdf'
    else  ||'_'||file_name||'.pdf' end file_name ,
    file_src,length(file_src) len,cd.doc_id,PRIORITY from
    MIM_CLIENT_DOCS CD,(select DOC_ID ,user_sequence from table P_DOC_AND_user_sequence ) TEMP_TAB
    WHERE CD.DOC_ID = TEMP_TAB.DOC_ID order by case when user_sequence is null then 1 else 0 end, file_name)                               
    loop
    insert into temp_trace values(i.file_name);
    L_OUT := UTL_FILE.FOPEN(v_oracle_dir,i.file_name,'wb',32760);
    end loop;I want my output as
    1_first attachment.txt
    2_second_attachment.docx
    3_abc.sql
    _xxx.txt  ------------------ When sequence is not assigned by user That is null at last.
    Unfortunately, I am not getting attachment in mail in this sequence. Can anyone give me suggestion.I see no code that attaches anything to email messages. What code is used to do this? Why are the files being written to the file system?

  • Sending mail with attachment and body.

    Hi Experts,
    I have a requirement of sending a mail with an attachment and also the mail will have a body whose content will be same as that in the attachment.Subject of the mail will also be configured dynamically.Though I am able to send the mail with the attachment but I am not able to configure the body whose content will be same as that of the attachment.
    I have unchecked the "Use Mail Package" and has hard-coded the "TO","From" field for sending the mail with attachment.
    Can you please check and let me know how to configure the body which will be same as that of the attachment.
    Thanks and Regards
    Atanu Mazumdar

    Hi,
    Use MTB module and then one of the parameter which can allow you to send message in attachment as well as in message body.
    Transform.ContentDisposition: it helps us to decide if we want to send the payload as an attachment or in the message body. If we give the Parameter value as u201Cattachmentu201D then we will have the payload attached in the mail and if we assign this value as u201Cinlineu201D the payload will go in the mail body.
    Hope this helps you..
    Regards....

  • Sending mail with Cc and copy in sent message box

    Since I have the last OS X 10.6.6 update, I dont receive anymore the Cc copy which I send to myself
    and have only the copy of the sent message in the sent box (messages envoyés)
    Similarly I cannot send a mail to myself as a verification process of my external mail provider. The copy is stored in the sent copy box, but it doesnt arrive in the in box (boite de reception)
    How can I get back to the former situation in which I could send copies to myself or send mail to myself
    Thanks for any hint
    Claude

    The first exception is this:
    http://java.sun.com/products/javamail/FAQ.html#norelay
    The second exception is probably due to a configuration error
    on the client. Turn on session debugging and the protocol
    trace will give some clues about what's wrong with the HELO
    command.

  • Problem sending mail with SMTP and SSL

    Hi,
    I am trying to send mail using JavaMail 1.4/jdk1.5 using ssl. I save the certificate by going into IE and exporting the certificate and added the certificate using the keytool to ${JAVA_HOME}/jre/lib/security/cacerts.I have also added this in the code using
    System.setProperty("javax.net.ssl.trustStore","${JAVA_HOME}/jre/lib/security/cacerts");But I am still getting the following error.
    DEBUG SMTP: trying to connect to host "XXXX", port 465, isSSL true
    DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
    Exception in thread "main" javax.mail.MessagingException: Exception reading response;
      nested exception is:
         javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
         at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
         at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
         at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
         at javax.mail.Service.connect(Service.java:275)
         at glycomics.common.util.SendMailUsingAuthentication.postMail(Unknown Source)
         at glycomics.common.util.SendMailUsingAuthentication.main(Unknown Source)
    Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
         at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:166)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1518)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1485)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1468)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1394)
         at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:86)
         at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
         at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
         at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
         at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
         at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
         ... 5 more
    Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
         at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:56)
         at sun.security.validator.Validator.getInstance(Validator.java:146)
         at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:105)
         at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:167)
         at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)
         at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:841)
         at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
         at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
         at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:818)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1030)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:678)
         at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
         ... 10 more
    Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
         at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:183)
         at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:103)
         at java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:87)
         at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:54)Has anybody faced similar problem??Any suggestions??
    TIA
    M
    Message was edited by:
    c@de-m@nkey

    See SSLNOTES.txt and the JavaMail FAQ for debugging hints.
    If you turn on all the debugging output and still can't figure it out,
    you'll probably need to ask in some Java security forum. The
    problem is occurring when making the connection using SSLSocket,
    before any JavaMail code comes into play.

  • Send Mail with xls AND pdf as attachment

    Hi there!
    I would lke to write a little program, which is able to send a xls-file AND a pdf-file within one mail.
    xls alone is already working fine, I'm using the method add_attachment of the class cl_document_bcs. But now I also want to add a pdf-File to this mail. The pdf file is on the local disk, so I'm uploading it via 'GUI_UPLOAD'. But now I have a problem because I don't know how I am able to add this to the mail.
    I hope you can help me!!
    Greetings,
    littlesam

    Hi,
    here a short extract:
    DATA: IT_BIN    TYPE SOLIX_TAB.
    DATA: WA_BIN    TYPE SOLIX.
    DATA: IT_LENGHT TYPE SO_OBJ_LEN.
    DATA: N10(10)   TYPE N.
    DATA: DOCUMENT  TYPE REF TO CL_DOCUMENT_BCS.
    DATA: WA_BCS    TYPE REF TO CX_BCS.
    DATA: ATT_TYPE  TYPE SOODK-OBJTP.
    DATA: SUBJECT   TYPE SO_OBJ_DES.
    DATA: P_FILE    LIKE RLGRAP-FILENAME VALUE 'C:\TEST.PDF'.
    DATA: FILE_NAME TYPE STRING.
    DATA: FILE_PATH LIKE PCFILE-PATH.
    *UPLOAD
    FILE_NAME = P_FILE.
    FILE_PATH = P_FILE.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
      EXPORTING
        FILENAME = FILE_NAME
        FILETYPE = 'BIN'
      CHANGING
        DATA_TAB = IT_BIN[].
    CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
      EXPORTING
        COMPLETE_FILENAME = FILE_PATH
      IMPORTING
        EXTENSION         = ATT_TYPE
        NAME              = SUBJECT.
    * ATTACHMENT
    DESCRIBE TABLE IT_BIN LINES N10.
    READ TABLE IT_BIN INDEX N10 INTO WA_BIN.
    N10 = ( N10 - 1 ) * 255 + STRLEN( WA_BIN ).
    IT_LENGHT = N10.
    TRY.
        CALL METHOD DOCUMENT->ADD_ATTACHMENT
          EXPORTING
            I_ATTACHMENT_TYPE    = ATT_TYPE
            I_ATT_CONTENT_HEX    = IT_BIN
            I_ATTACHMENT_SIZE    = IT_LENGHT
            I_ATTACHMENT_SUBJECT = SUBJECT.
    * Error abfangen
      CATCH CX_BCS INTO WA_BCS.
        WRITE: 'Fehler aufgetreten.'(001).
        WRITE: 'Fehlertyp:'(002), WA_BCS->ERROR_TYPE.
        EXIT.
    ENDTRY.
    You can use it for every local file
    Hope it helps.
    regards, Dieter

  • TS3276 I'M unable to send mail with yahoo and gmail accounts. any clues why? any help?

    Need help with MacPro mail and sending email currently not functioning.

    Troubleshooting sending and receiving email messages
    Troubleshooting sending email messages

  • HT4864 Mail client can't send mail with @me and @icloud

    Why my mail account @icloud or @me don't work well with my mai client (windows live mail 2012)? I've setted the right parameters, but i can only recive the email, when i try to send it the account don't work! I've setted the mail client with this parameters:
    IMAP (Incoming Mail Server) information:
    Server name: imap.mail.me.com
    SSL Required: Yes
    Port: 993
    Username: [email protected] (use your @me.com address from your iCloud account)
    Password: Your iCloud password
    SMTP (outgoing mail server) information:
    Server name: smtp.mail.me.com
    SSL Required: Yes
    Port: 587
    SMTP Authentication Required: Yes
    Username: [email protected] (use your @me.com address from your iCloud account)
    Password: Your iCloud password

    The following link may provide help...
    http://apple.stackexchange.com/questions/35350/how-can-i-add-my-icloud-email-acc ount-in-windows-live-mail

  • Sending Mail with ActiveX and Outlook2K

    I need to be able to send a message from LabVIEW using Outlook2K. I've found the ActiveX, Outlook vi's on the dev zone and the "Create Outlook Mail Message.vi" almost works.
    The VI creates the message correctly, but it doesn't actually send the message, it just places it in the 'Outbox' and it just sits there. The only way to actually send it is to go to the Outbox, double click the message to open it, and hit the send button.
    This is being used as an alert message so it needs to be sent automatically with no user intervention. We do not have STMP mail access here so that's not an option.
    Is there something I'm missing in the ActiveX setup, or is this just yet another Outlook problem. I can't find an option to set in Out
    look to send right away, or not use the outbox.
    Any thoughts?
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

    Never mind, I figured it out myself.
    The problem was the DeferredDeliveryTime attribute of the _MailItem property. I was setting this the current time and date thinking that would make it send immediately.
    It doesn't seem to work that way. I fixed it by making that attribute read instead of write, and the message is sent right away.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • How to send mail with cc and attachment

    please provide code for sending a file with attchment in cc also

    HI Rajesh,
    There is a standard structure for Receiver Mail adopter which we can get from SAP market Place but it is not provided with CC if u want to use CC then you have to go with Dynamic Configuration.
    DynamicConfiguration configuration = (DynamicConfiguration) container.getTransformationParameters().getStreamTransformationConstants.DYNAMIC_CONFIGURATION);
    /*any other required fields*/
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/Mail", "THeaderCC");
    configuration.put(key, "ccemail @ test.com");
    Regards
    Praveen Reddy
    Edited by: Maareddy Praveen Reddy on Aug 10, 2011 12:17 PM

  • Thunderbird can download and send mail with Cox POP Mail, Mail cannot?

    I have Thunderbird and Mail installed.
    I can download and send mail with Thunderbird.
    I can't even set-up an account with Mail because it cannot find the POP Mail server.
    I have Firewall on with ports 25, 110 and 587 open.
    This really seems strange that I can use Thunderbird to set up and use POP Mail access to Cox, but not Mail.
    My servers are:
    pop.central.cox.net
    smtp.central.cox.net
    I've followed the steps on Cox's support web site, no success.
    I've already called Cox, they're clueless.
    Thoughts or suggestions are greatly appreciated.
    Thanks,
    --Todd
    Mini   Mac OS X (10.4.6)  

    Hi Todd,
    Well since Tbird works, we can rule out lots of things.
    Mail cannot find the POP server
    You are using the Welcome to Mail assistant to do this, and when you type in your incoming mail server info it spins the gear a bit, gives an error, and says that if you continue Mail may not work -- yes? What does the error say specifically?
    No disrespect at all, but the most likely problem is a typo somewhere / mis-specified username. Please go 'round once more.
    Good luck,
    John

  • How do I connect to remote mac with ard without being prompted for username and pasword

    I setup my Mac Pro to connect to my Macbook Pro (both on snow leopard at the time) with apple remote desktop when I used to select control on my Mac Pro I used to be able to start controlling my MBP straght away with out needing to enter a username or pasword.
    When Lion came out I upgraded my Mac Pro and left my MBP on snw leoprd no settings on my MBP were changed I installed the ARD control software on my Mac Pro and when I clicked control I was requested to enter a username and password.
    Does anyone know why I can no longer control my MBP without entering a username and pasword and how to setup ARD to allow me to do that?

    Create a text file with name boot.properties in the directory <Domain_Home>/servers/<Server_Name>/security. The file must contain the following:
    username=<username>
    password=<password>
    Replace <username> and <password> with the username and password of an WLS admin user (e.g. weblogic). They will be encrypted automatically by WLS at first boot.
    Dimitar

  • Sending mail with attachment fails on MAC Mail and WRP400.

    Sending mail with attachment fails on MAC Mail and WRP400.
    We have hundreds of WRP400 connected with Mac (Machintosh) computers. No special configurations are applied (no virtual server or DMZ). Web navigation, P2P programs and sending mail without attachment work right.
    The problem is the impossibility to send mails with medium or big size files attachment from MAC Mail.
    If we use Windows PCs or a different linksys routers (eg. WRT54G) the problem not happens.
    We have upgraded WRP400 firmware version from 1.00.06 to 2.00.05 but the result is the same. Sending mail with attachment using Mac fails.
    We tried to configure WRP400 with DMZ to a particular MAC. We tried to configure Virtual server on tcp 25 port of a MAC. The result is always the same.
    This is a WRP400 bug? Windows PCs work right. MAC and MAC mail works right with other linksys router.
    We need help. Thanks.

    The problem was fixed since beta firmware 2.00.11.
    I think that this issue was caused from a bug that decrease upload bitrate of WRP400 after some days of activity.
    See more details on Cisco forum under title "WRP400 stops responding after browsing certain websites".
    Thanks.

  • Receive a mail with attachment and send it as it is via Mail-receiver

    Hi,
    we have PI/7.0
    I have a scenario with a mail-sender.
    I get mails with attachments and depending on the subject I have to send some mails to an other mail-address via mail-receiver-adapter.
    My problem is, that I have to send it "as it was" - with all attachments (and the correct attachment names) and the original mail-body.
    I tried to check the checkbox "keep attachments": I got all attachments but the original mail-body was now an extra attachment (with the extension .xml).
    I don't wanna have this new attachment!
    What can I do?
    Thanx a lot!
    Regards
    Wolfgang

    Hi,
    I think quite simple
    message protocol: xipayload
    Use Mail package: NO
    Keep Attachments: YES
    Content encoding: <nothing>
    No extra modul
    I entered all address-informations (from, to,...) in the fields displayed after the checkbox for "use mail package".
    that's all.
    regards
    Wolfgang

Maybe you are looking for