zoukankan      html  css  js  c++  java
  • How to enables AX email functionality without Outlook

    /*****************************************************************
      (C) Copyright DENTSPLY International. All rights reserved.
      The use, disclosure, reproduction, modification, transfer, or
      transmittal of this work for any purpose in any form or by any
      means without written permission of DENTSPLY International is
      strictly prohibited.
    
      Created Date: 10/Jun/2013
      Created By: Jimmy Xie[Tectura]  
      Helpdesk Ticket#: KP000115
      Description of Behavior: Enables AX email functionality without Outlook
      Expected Input: Request to generate email
      Expected Output: Email sent out of AX
    ******************************************************************/
    
    void reportSendMail(PrintJobSettings p1)
    {
        //Start Declaration
        //SysINetMail m = new SysINetMail();     // Commented out old AX code
        System.Net.Mail.MailMessage             mailMessage;
        System.Net.Mail.Attachment              attachment;
        System.Net.Mail.AttachmentCollection    attachementCollection;
        System.Net.Mail.SmtpClient              myMail;
        str                                     userMailAddress;
        str                                     receiverMailAddress;
        str                                     receiverCCMailAddress;
        str                                     mailBody;
        str                                     smtpServer;
        str                                     mail;
        fileNameOpen                            fileNameForEmail;
        FileIOPermission                        perm;
        userinfo                                userInfo;
        //end Declaration
        str                                     fileName = 'axaptareport';
        SysEmailMessageTable                    sysEmailMessageTable;
        ;
    
        if (p1.format() == PrintFormat::ASCII)
        {
            fileNameForEmail = subStr(p1.fileName(),strLen(p1.fileName())-3,-999) + 'TXT'; // NL
        }
        //fileName = fileName + '.txt'; // Commented out this line
    
        else if (p1.format() == PrintFormat::RTF)
        {
            fileNameForEmail = subStr(p1.fileName(), strLen(p1.fileName())-3, -999) + 'RTF';
        }
        //fileName = fileName + '.rtf';
    
        else if (p1.format() == PrintFormat::HTML)
        {
            fileNameForEmail = subStr(p1.fileName(), strLen(p1.fileName())-3, -999) + 'HTM';
        }
        //fileName = fileName + '.htm';
        //else if (p1.format() == PrintFormat::PDF) // Performance Testing : commentign this line and replacing the line below.
        else if (p1.format() == PrintFormat::PDF || p1.format() == PrintFormat::PDF_EMBED_FONTS)// Performance Testing :(replacing the above line) addign this line as it was present in the jsRemotecontroller project.. can be removedd later..
        {
            fileNameForEmail = subStr(p1.fileName(), strLen(p1.fileName())-3, -999) + 'PDF';
        }
    
        //fileName = fileName + '.pdf';
        //Start Logic
        mail = subStr(fileNameforEmail, (strlen(fileNameforEmail)-8), 9);
    
        select firstonly name from userInfo where userInfo.id == SysuserInfo::find().Id; // to find the user name
    
        fileNameforEmail = winApi::getTempPath() + mail; // store attachment in a temp location
    
        perm = new FileIOPermission(fileNameforEmail, 'w');
    
        if(!perm)
        {
            throw error("Cannot move attachment to temp location.");
        }
    
        try
        {
            perm.assert();
        }
        catch
        {
            throw error("Cannot gain access to Temp location.");
        }
    
        // find current users email address setup up in user //options
        userMailAddress         = SysUserInfo::find().Email;
    
        if(!info::validateEmail(userMailAddress))
        {
            throw error("Senders email is not valid");
        }
    
        receiverMailAddress     = p1.mailTo() + "," + p1.mailCc();
        receiverMailAddress     = strReplace(receiverMailAddress, ";" , ",");
    
        mailBody = SysEmailMessageTable::find("SysEmail", SysEmailTable::find("SysEmail").DefaultLanguage).Mail;
    
        // using the SMTP server ip //setup in email Parameters
        smtpServer              = SysEmaiLParameters::find(false).SMTPRelayServerName;
    
        try
        {
            mailMessage             = new System.Net.Mail.MailMessage(userMailAddress, receiverMailAddress);
        }
        catch(Exception::Internal)
        {
            infolog.clear(0);
            throw error("This Message was undeliverable due to the following reason:"
                        +"
    "
                        +"Your message was not delivered because a destination address was
    "
                        +"not found.  Carefully check that it was spelled correctly and try
    "
                        +"sending it again if there were any mistakes.
    "
                        +"
    "
                        +"**When separating multiple email address please use either a comma or semicolon.**"
                       );
        }
    
        mailmessage.set_Subject(p1.mailSubject());
        mailmessage.set_Body(mailBody);
    
        mailmessage.set_IsBodyHtml(true);
    
        //move attachment file to Temp folder
        winapi::moveFile(p1.fileName(), fileNameforEmail);
    
    
    
    
        attachementCollection = mailMessage.get_Attachments();
        attachment = new System.Net.Mail.Attachment(fileNameforEmail);
        attachementCollection.Add(attachment);
    
        myMail = new System.Net.Mail.SmtpClient(smtpServer);
        mymail.Send(mailmessage);
    
        //Disopse COM objects
        attachment.Dispose();
    
        attachementCollection.Dispose();
        mailMessage.Dispose();
    
        //Delete the temp file
        winApi::deleteFile(fileNameforEmail);
        CodeAccessPermission::revertAssert();
        //end
    }
  • 相关阅读:
    配置PL/SQL Developer连接Oracle数据库
    解决RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large问题
    解决java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList问题
    解决spring mybatis 整合后mapper接口注入失败
    如何解决Failed to start component [StandardEngine[Catalina].StandardHost[127.0.0.1].StandardContext[]]问题
    五毛的cocos2d-x学习笔记05-场景与场景动画,动作
    五毛的cocos2d-x学习笔记04-触摸点
    五毛的cocos2d-x学习笔记03-控件
    五毛的cocos2d-x学习笔记02-基本项目源码分析
    五毛的cocos2d-x学习笔记01-创建项目
  • 原文地址:https://www.cnblogs.com/Fandyx/p/3200180.html
Copyright © 2011-2022 走看看