Looking to send an e-mail using 365. I need to add an attachment.

Here is what I has so far and I am very close. I have tried many things. I added
$attachment = New-Object System.Net.Mail.Attachment("XXXXX")
But didn't work. The script below works for me I just need to add an attachment.
$EmailFrom = "XXXX.com"
$EmailTo = "XXXXX.com"
$Subject = "Testing"
$Body = "Thisisatest"
$SMTPServer = "XX.XXX.XXX.XXX"
$SMTPClient = New-Object Net.Mail.SmtpClient("Thisissmtp")
$SMTPClient.EnableSsl = $true
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Hi,
What was in your 'XXXXX' (not exactly helpful, btw)?
Take a look at this article, which has an example of how to do this:
http://www.techrepublic.com/blog/windows-and-office/send-an-email-with-an-attachment-using-powershell/4969/#.
Reference:
http://msdn.microsoft.com/en-us/library/system.net.mail.attachment%28v=vs.110%29.aspx
EDIT: Also, why not just use
Send-MailMessage?
Don't retire TechNet! -
(Don't give up yet - 12,575+ strong and growing)

Similar Messages

  • How to send HTML Format Mail using Java Mail in oracle 9i Forms

    Dear All
    could you please tell me how to send HTML Format Mail using Java Mail in oracle 9i Forms and how to implement the java mail ?
    if it is possible, could you please send me the sample code? please very urgent
    Thanks
    P.Sivaraman

    Hello,
    <p>Here is a Form sample.</p>
    Francois

  • Sending an e-mail using java

    Hi,
    I am sending an e-mail using java. It works fine, but I wanted to know if there is any possibility to attach a document, without using a File object. Because I have to write the File object and then delete it at the end. I would like to know if I can use for example a byte [], or something else.
    Thank you very much.
    This is my code, if that helps.
    public static void sendWithAttach(String p_sender, String p_receiver, String p_subject,
    String p_comment, int p_nombrePiecesJoints, HashMap<String, byte[]> p_files) {
    Properties props = System.getProperties();
    props.put("mail.smtp.host", Solapcore.getCurrent().getServletConfig().getServletContext().getInitParameter("SMTP"));
    Session session = Session.getDefaultInstance(props, null);
    MimeMessage sender = new MimeMessage(session);
    MimeBodyPart mbp1 = new MimeBodyPart();
    Multipart mp = new MimeMultipart();
    List<File> listeFiles = new ArrayList<File>();
    try {
    //On assigne to, from, subject, body, priority
    sender.setRecipients(javax.mail.Message.RecipientType.TO,
    InternetAddress.parse(p_receiver, false));
    sender.setFrom(new InternetAddress(p_sender));
    sender.setSubject(p_subject);
    mbp1.setText(p_comment);
    //sender.setPriority(0);
    mp.addBodyPart(mbp1);
    //On attache les documents
    for(Map.Entry<String, byte[]> entry : p_files.entrySet()) {
    MimeBodyPart mbp2 = new MimeBodyPart();
    String fileName = entry.getKey();
    byte [] dataFile = entry.getValue();
    File file = new File(fileName);
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(dataFile);
    mbp2.attachFile(file);
    mbp2.setFileName(fileName);
    mp.addBodyPart(mbp2);
    listeFiles.add(file);
    sender.setContent(mp);
    Transport.send(sender);
    }catch(MessagingException mex) {
    mex.printStackTrace();
    }catch(FileNotFoundException fnf) {
    fnf.printStackTrace();
    }catch(IOException ioe) {
    ioe.printStackTrace();
    }finally {
    Iterator<File> itListeFiles = listeFiles.iterator();
    while(itListeFiles.hasNext()) {
    File tempFile = (File)itListeFiles.next();
    tempFile.delete();
    }

    Thank you very much.
       public static void sendWithAttach(String p_sender, String p_receiver, String p_subject,
          String p_comment, int p_nombrePiecesJoints, HashMap<String, byte[]> p_files) {
        Properties props = System.getProperties();
        props.put("mail.smtp.host", Solapcore.getCurrent().getServletConfig().getServletContext().getInitParameter("SMTP"));
        Session session = Session.getDefaultInstance(props, null);
        MimeMessage sender = new MimeMessage(session);
        MimeBodyPart mbp1 = new MimeBodyPart();
        Multipart mp = new MimeMultipart();
        List<File> listeFiles = new ArrayList<File>();
        try {
          //On assigne to, from, subject, body, priority
          sender.setRecipients(javax.mail.Message.RecipientType.TO,
              InternetAddress.parse(p_receiver, false));
          sender.setFrom(new InternetAddress(p_sender));
          sender.setSubject(p_subject);
          mbp1.setText(p_comment);
          //sender.setPriority(0);
          mp.addBodyPart(mbp1);
          //On attache les documents
          for(Map.Entry<String, byte[]> entry : p_files.entrySet()) {
            MimeBodyPart mbp2 = new MimeBodyPart();
            String fileName = entry.getKey();
            byte [] dataFile = entry.getValue();
            File file = new File(fileName);
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(dataFile);
            mbp2.attachFile(file);
            mbp2.setFileName(fileName);
            mp.addBodyPart(mbp2);
            listeFiles.add(file);
          sender.setContent(mp);
          Transport.send(sender);
        }catch(MessagingException mex) {
          mex.printStackTrace();
        }catch(FileNotFoundException fnf) {
          fnf.printStackTrace();
        }catch(IOException ioe) {
          ioe.printStackTrace();
        }finally {
          Iterator<File> itListeFiles = listeFiles.iterator();
          while(itListeFiles.hasNext()) {
            File tempFile = (File)itListeFiles.next();
            tempFile.delete();
        }

  • Trying to print e-mails using iCloud but can not add my printer Epson Stylus Photo PX810FW Why not?r

    Trying to print e-mails using iCloud but can not add my printer Epson Stylus Photo PX810FW
    Why not?

    Trying to print e-mails using iCloud but can not add my printer Epson Stylus Photo PX810FW
    Why not?

  • Mail freezes when I want to add an attachment with my mail.

    Since I installed OS 10.9 mail freezes when I want to add an attachment with my mail. How can this be resolved?
    My iMac is from mid 2007 with 4 GB internal memory and 1 TB of diskspace of which 45% is used.

    Go to Settings>Store, tap the ID shown, sign out, sign back in with the ID you want to use.

  • Can you send encrypted e-mails using SO_NEW_DOCUMENT_ATT_SEND_API1

    We use SO_NEW_DOCUMENT_ATT_SEND_API1 to send e-mails to employees for various notifications.  The e-mails go out through SCOT and are sent to our lotus notes.
    We have a project being implemented, where the data we are sending in the note is kind of sensitive, so we'd like to see if we could send the e-mail as encrypted.   Does anyone know if there is some parameter we can set upon sending that would encrypt the text in the e-mail for sending?

    FORM pssword_prot_encryptpdf .
      DATA: BEGIN OF command_list OCCURS 0.
              INCLUDE STRUCTURE sxpgcolist.
      DATA: END OF command_list .
      DATA: BEGIN OF exec_protocol OCCURS 0.
              INCLUDE STRUCTURE btcxpm.
      DATA: END OF exec_protocol.
      DATA: status LIKE btcxp3-exitstat,
      commandname LIKE sxpgcolist-name VALUE 'ZTEST',
      sel_no LIKE sy-tabix.
    * GET LIST OF EXTERNAL COMMANDS
      CALL FUNCTION 'SXPG_COMMAND_LIST_GET'
        EXPORTING
          commandname     = commandname
          operatingsystem = sy-opsys
        TABLES
          command_list    = command_list
        EXCEPTIONS
          OTHERS          = 1.
      CALL FUNCTION 'SXPG_COMMAND_CHECK'
        EXPORTING
          commandname                = command_list-name
          operatingsystem            = sy-opsys
        EXCEPTIONS
          no_permission              = 1
          command_not_found          = 2
          parameters_too_long        = 3
          security_risk              = 4
          wrong_check_call_interface = 5
          x_error                    = 6
          too_many_parameters        = 7
          parameter_expected         = 8
          illegal_command            = 9
          communication_failure      = 10
          system_failure             = 11
          OTHERS                     = 12.
      CLEAR command_list.
      REFRESH command_list.
      DATA: v_dir_input      TYPE sxpgcolist-parameters.
      DATA: v_dir_input1      TYPE sxpgcolist-parameters.
      break developer.
      command_list-name = 'ZTEST'.
      command_list-opsystem = 'Windows NT'.
      CONCATENATE   'd:\pdf\' main_dtl-vbeln '.PDF' INTO name.
      CONCATENATE 'cmd /c d:\pdf\encryptpdf.exe' '-i' name  '-o ' name  '-u'  hdr-password INTO v_dir_input SEPARATED BY space .
      READ TABLE command_list INDEX sel_no.
      break developer.
      CONCATENATE command_list-opcommand v_dir_input INTO command_list-opcommand SEPARATED BY space.
    * CHECK AUTHORIZATION
      command_list-addpar = 'X'.
      APPEND command_list.
      CONSTANTS: c_extcom    TYPE sxpgcolist-name VALUE 'ZTEST',
                 c_oper      TYPE syopsys VALUE 'Windows NT'.
      DATA: t_result         TYPE STANDARD TABLE OF btcxpm.
      v_dir_input  =  command_list-opcommand.
      CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
        EXPORTING
          commandname                   = c_extcom
          additional_parameters         = v_dir_input
          operatingsystem               = c_oper
        TABLES
          exec_protocol                 = t_result
        EXCEPTIONS
          no_permission                 = 1
          command_not_found             = 2
          parameters_too_long           = 3
          security_risk                 = 4
          wrong_check_call_interface    = 5
          program_start_error           = 6
          program_termination_error     = 7
          x_error                       = 8
          parameter_expected            = 9
          too_many_parameters           = 10
          illegal_command               = 11
          wrong_asynchronous_parameters = 12
          cant_enq_tbtco_entry          = 13
          jobcount_generation_error     = 14
          OTHERS                        = 15.
    ENDFORM.                    " PSSWORD_PROT

  • Sateillite A200-1A9: Issue with sending/receiving E-mail using Windows Mail

    Using Windows mail I have to close/open the programme to be able to send mails, they get stuck in the Outbox. By closing and reopening the programme the mail gets sent. Also the Blue figure 1 in brackets showning 1 unread mail in the Outbox is there all the time although there is no mails read or unread in the Outbox
    Not a server problem as all mails are going/receiving fine on my desktop.
    Pressing send and receive button does not help. although some of the time it will receive mails when pressing send/receive but will not send them
    I do have Norton Internet security 2007 and am getting fed up with the continuing problems that this seems to cause over the period 2004-7.
    Is there an issue with the Windows mail programme running with Vista that is known

    I think I have found a solution
    Please check this:
    Windows Mail will not Send or Receive mails
    http://support.toshiba-tro.de/kb0/TSB7701X30005R01.htm
    It seems that the update of Software Desktop SMS to the newest version will help to sort out this problem.

  • HT3783 I have created a distribution list of 22 names in my Contacts Folder.  When I try to send an e-mail using the alias, only 7 of the 22 names appear in the address line.  Why don't all the names appear?

    I have created a mail box with 22 names in it.  When I want to send an e-mail to this address and its recipients, only 7 of the 22 names appear in the address line of the e-mail.  Why won't the remaining 15 names and addresses appear in the address line?

    okay, this is actually a common problem.  from your main screen select the blackberry key (next to track ball)->options->security->general settings->include address book->no->reset phone->problem should be fixed!
    let me know if this works for you,
    Andrew
    Andrew Hager
    U.S. Cellular Corporation
    Smartphone Specialist

  • When sending an email I used to be able to add a distribution list from my contacts, I now have to add each email address individually, does anyone know how I can add the whole list?

    When sending an email I used to be able to click on a distribution list in my contacts and it would add all the email addresses, I now have to add each email address individually and this takes a lot of time.  Could someone tell me how I can add a distibution list/group to my emails?

    Barney,
    I have four groups.
    I just typed the name of one of those groups in the To field on the iPhone's email, and received:
    Invalid Address
    "<group name>" does not appear to be a valid email address.  Do you want to send it anyway?
    I clicked continue and it remains in my outbox.
    Help is appreciated.
    Thanks,
    Michael

  • Cannot send emails from Mail- using yahoo email - please help!!

    I'm having major problems with my yahoo email in Mail. No matter what settings i seem to use, any emails i send take hours and hours to arrive. I seem to be receiving email, but cannot send- sometimes i get an error message, other times they go into sent box but take hours or days to arrive. i'm using a brand new imac version 10.5.2

    Hello Fred.
    If you’re sure your settings are exactly the same as on the computers where it works, here a couple of things that you may want to look at.
    Go to Apple Menu > System Preferences > Network, choose Network Port Configurations from the Show popup menu, and make sure that the configuration used to connect to Internet appears at the top of the list.
    Also, try using a different method to connect to Internet, if possible, or connecting the computer to Internet as directly as possible, i.e. bypassing any routers that might be present, using an ethernet cable instead of wireless, etc., and see whether that makes a difference.
    Mail keeps information about outgoing servers in a separate list, independently of any specific mail account. The account settings just associate one of the available outgoing servers with each account. Orphaned or dangling outgoing server entries (i.e. not associated with any account) sometimes cause weird sending problems.
    Go to Mail > Preferences > Accounts > Account Information > Outgoing Mail Server (SMTP), choose Edit Server List from the popup menu, and delete any servers that shouldn’t be there. The Edit Server List panel shows the account each outgoing server is associated with.

  • Cannot send attachments in Mail using .mac account, pop account is fine!

    Within my Mail.app, I have 2 accounts: one is a .mac account, the other a pop account.
    When I send attachments (jpg always and sometimes pdf) with the .mac account, they do not get encoded properly and my recipients cannot view them -- or they can view, say, 10% of the photo.
    When I send the same attachments with the pop account, and within the same Mail.app, I do NOT have this problem.
    Furthermore, if I send the attachment from my .mac webmail, I do NOT have the problem.
    Does Mail.app have a problem with attachments sent via IMAP accounts?
    I have tried Repairing Permissions, deleting the outbox.mbx (and emptying the trash).
    Does anyone have any other suggestions? This is driving me crazy.
    I am running Mail 2.0.5 on Tiger 10.4.3
    Thanks a lot in advance, Neil
    Long live the sunflower iMac, iBook G4   Mac OS X (10.4)  

    Hello Neil.
    Does Mail.app have a problem with attachments sent via IMAP accounts?
    None that I'm aware of.
    The Mail.app uses MIME 1.0 for message/attachment encoding (which is the internet standard) for all email accounts.
    Is your POP account and the SMTP server used for the account provided by your ISP used for connecting to the internet?
    If so, try selecting/using your ISP's SMTP server (the same SMTP server used to send mail via your ISP's POP account) to send mail via your .Mac account as a test.

  • Sending HTML E Mail using Java Mail

    Can anybody please tell me how to send HTML email using JavaMail. I know I need the DataContentHandler for text/html mime type but where can I find one? If anybody has better suggestions you are welcome.

    Folks,
    I've used what you have suggested. Though it compiled, I kept getting this java error
    --Exception in MailServer.java
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
    javax.mail.MessagingException: IOException while sending message;nested exception is:
    javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/html
    at javax.mail.Transport.send0(Transport.java:204)
    at javax.mail.Transport.send(Transport.java:73)
    at MailTest.send(MailTest.java:419)
    at MailTest.sendThruDefaultServer(MailTest.java:319)
    at MailTest.main(MailTest.java:476)
    [sendEmail() - Exception  :javax.activation.UnsupportedDataTypeException
    HELP!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Can't send or receive mail using mail

    I am posting for a new Mac user. We don't know all the terms so please be patient. She can get to webmail at sbc..... and use but can't use Mail to send or recieve. Help!
    ibook running Tiger 10.4.4
    dialup connection with sbcglobal.....
    can use SBC webmail
    have checked pop and smtp connections with sbc
    Sbc says they can't help don't have mac mail instructions
    Can anyone help? Is there something we are missing?
    What good are they if they can't help?
    rosieag

    Authentication my ISP set to None in Mail---and
    tutorial has no such thing authentication for her in
    server settings? Also, under advanced
    authentication mine is Password and the tutorial has
    ........(for password) I assume. We entered her
    password.
    We know the ports are important. Hers are set to 25
    and 25. SSL is not checked
    Help me keep straight on your setting versus hers. For the sbcglobal, in Advanced the Port should be 110 -- this is for the Incoming POP3 server.
    In the Server Settings for the Outgoing server, the Port should be 25, and the Authentication set to Password, and the Username entry should be the full email address (this is different for some ISP, but SBC instructs to use the full email address), and of course the Password. In both place where Username is required, it should be the entire email address for her sbcglobal.
    Have I missed anything? Do you still have your setup working AOK?
    Ernie
    BTW, I am a 61 year old, grandfather, but perhaps a little geekier than some!

  • How send attachments to mail using oracle alerts

    Hi All,
    I am working on Oracle Alerts in oracle applications. how to send attachment to mail.
    Thanks in Advance,
    Reddy.
    Edited by: user9540785 on Mar 22, 2009 4:48 AM

    As a workaround, you can kick start a custom workflow in actions rather than sending mail. In that custom workflow you can send attachments as part of the notification to the respective recipients.
    Thanks
    Nagamohan

  • Sender Address For Mail using BCS

    Hi All,
    Currently we are using SET_SENDER method of CL_BCS for setting the sender address while sending email using BCS.
    But this method retrieves the Email ID of the sender from the Default User Settings. Instead, we need to set the sender email ID from the internet address mentioned in the HR Info Type.
    It would be even better, if we have option to set any arbitrary Email address like '[email protected]' instead of the user id.
    Please let me know if any such option is available.
    Thanks,
    Anand

    bump...
    Anyone got a fix for this? Vacation auto-reply is being bounced by 3rd party relay server due to malformed sender address.

Maybe you are looking for