小编Yur*_*yko的帖子

在python 3中更改发件人帐户ms Outlook

我在 ms Outlook 中有 2 个帐户('user1@test.com' - 默认配置文件,'user2@test.com'),我正在尝试使用非默认帐户通过 python 发送消息。这是我的代码:

Import win32com.client
app = win32com.client.Dispatch('Outlook.application')

mess = app.CreateItem(0)
mess.to = 'user2@test.com'
mess.subject = 'hi'
mess.SendUsingAccount = 'user2@test.com'
mess.Send()
Run Code Online (Sandbox Code Playgroud)

Outlook 是从帐户“user1@test.com”发送的,而不是从“user2@test.com”发送的。如何更改账户?

outlook pywin32 python-3.6

5
推荐指数
1
解决办法
4311
查看次数

Javascript中如何通过Proxy调用对象方法?

我有课:

class Course {
  constructor(name) {
    this._name = name;
  }

  getName() {
    return this._name;
  }
}
Run Code Online (Sandbox Code Playgroud)

我想围绕类 Course 创建一个代理,它将仅返回非私有字段和方法:

const handlers = {
  get: (target, prop, reciever) => {
    if (prop in reciever && prop[0] !== '_' ) {
      if (typeof reciever[prop] === 'function') {
        return reciever[prop].apply(reciever);
      } else {
        return reciever[prop];
      }
    } else {
      throw new Error('problem');
    }
  }
}

const protect = (obj) => {
  return new Proxy(obj, handlers);
}
Run Code Online (Sandbox Code Playgroud)

但是当我调用对象方法时:

const protectedCourse = protect(new Course('Test'));
console.log(protectedCourse.getName()); …
Run Code Online (Sandbox Code Playgroud)

javascript

5
推荐指数
1
解决办法
3992
查看次数

如何在 Express/node js 中发送错误响应?

我有快递服务器。当我发送获取请求时,我使用中间件功能授权来检查数据库中该用户的令牌。但是,我有一个问题:当我尝试发送响应错误时,我的响应向我发送了一个空对象,但是 console.log 向我显示了错误!我究竟做错了什么???这是我的代码:

const auth = async(req,res,next)=>{
try {
    const token = req.header('Authorization').replace('Bearer ','')
    const decode_token = jswt.verify(token,'mytoken')
    const user =await User.findOne({"_id": decode_token._id, "tokens.token":token})


    if (!user){
        throw new Error('Please autorizate')
    }

    req.token = token
    req.user = user

    next()
} catch (error) {
    console.log(error)
    res.status(401).send({"err":error})
}
Run Code Online (Sandbox Code Playgroud)

}

node.js express

3
推荐指数
2
解决办法
3736
查看次数

如何在Java中创建相对路径?

我有根目录和嵌套在根目录中的文件(它们可以在子目录中)。我想创建这些文件的相对路径列表。我写了代码,但替换不起作用。

public class FileManager {
private Path rootPath;
private List<Path> fileList = new ArrayList<Path>();

public FileManager(Path rootPath) throws IOException{
    this.rootPath = rootPath;
    collectFileList(rootPath);
}

private void collectFileList(Path path) throws IOException{
    if (Files.isRegularFile(path)){
        if (!fileList.contains(path.getParent())){
                String result_path =  path.toAbsolutePath().toString().replaceAll(rootPath.toString(),"");
                fileList.add(Paths.get(result_path));
        }
    }else if (Files.isDirectory(path)){
        for (File file:path.toFile().listFiles()
             ) {
            collectFileList(Paths.get(file.getAbsolutePath()));
        }

}
}
Run Code Online (Sandbox Code Playgroud)

例如:我有根目录“E:\test”,我有文件“E:\test\test2\1.txt”。我想替换路径文件的根目录,并返回“test2\1.txt”。但我总是收到“E:\test\test2\1.txt”。我的替换有什么问题?

java

1
推荐指数
1
解决办法
54
查看次数

标签 统计

express ×1

java ×1

javascript ×1

node.js ×1

outlook ×1

python-3.6 ×1

pywin32 ×1