从Windows Task Scheduler启动时,使用Outlook的应用程序无法发送电子邮件

时间:2019-05-05 18:36:14

标签: c# outlook

我构建了一个小型应用程序,该应用程序会定期向不同的收件人发送电子邮件。

使用C#代码非常简单:

public class CalcFrame extends JFrame {

    private JTextField input1;
    private JTextField input2;
    private JTextField output1;
    private JButton add;
    private JButton subtract;
    private JButton multiply;
    private JButton divide; 
    private Calc theCalc;

    private class ActionAdd implements ActionListener {
        public void actionPerformed(ActionEvent arg0) {
            theCalc.setInput1(Double.parseDouble(input1.getText()));
            theCalc.setInput2(Double.parseDouble(input2.getText()));
            theCalc.add();
            output1.setText(String.valueOf(theCalc.getOutput1()));
        }
    }
    private class ActionSubtract implements ActionListener {
        public void actionPerformed(ActionEvent arg0) {
        }
    }
    private class ActionMultiply implements ActionListener {
        public void actionPerformed(ActionEvent arg0) {
        }
    }
    private class ActionDivide implements ActionListener {
        public void actionPerformed(ActionEvent arg0) {
        }
    }
    public CalcFrame() {
        super();
        theCalc = new Calc(); // I believe this is the theCalc variable to reference the instance of the Calc class
        Container contentPane = getContentPane();
        input1 = new JTextField(10);
        input2 = new JTextField(10);
        JPanel inPanel = new JPanel();
        inPanel.add(input1);
        inPanel.add(input2);
        contentPane.add(inPanel,BorderLayout.NORTH);

        output1 = new JTextField(10);
        contentPane.add(output1,BorderLayout.CENTER);

        add = new JButton("+");
        add.addActionListener(new ActionAdd());
        subtract = new JButton("-");
        subtract.addActionListener(new ActionSubtract());
        multiply = new JButton("*");
        multiply.addActionListener(new ActionMultiply());
        divide = new JButton("/");
        divide.addActionListener(new ActionDivide());
        JPanel buttonPanel = new JPanel();
        buttonPanel.add(add);
        buttonPanel.add(subtract);
        buttonPanel.add(multiply);
        buttonPanel.add(divide);
        contentPane.add(buttonPanel,BorderLayout.SOUTH);
    }
    public CalcFrame(String title) {
        this();
        setTitle(title);
    }
}

当我运行计算机上的.exe时,它会成功发送一封电子邮件,但是从任务计划程序运行该电子邮件时会遇到一些错误。

这是任务计划程序运行此exe的结果 enter image description here

此外,它没有遇到任务计划程序中的某些异常,似乎只是在超时,我想是在等待Outlook的某些权限。

还将Outlook编程访问权限设置为:

enter image description here

===================================

Edit1:程序正在超时@ OutlookApp outlookApp = new OutlookApp();

1 个答案:

答案 0 :(得分:1)

确保已将任务计划程序任务配置为使用正确的计算机/网络/域帐户运行(例如,在计算机上运行应用程序时输入的凭据)。本地系统帐户(Windows默认)不在此类别下。