D语言新手问题 D语言发送邮件代码

· Created · Last modified by 云峰 replied at · 1050 times read
    // 邮件
    @Action string sendMail(){
        import arsd.email;
        import std.typecons;
        RelayInfo mailServer;
        mailServer.server = "smtps://smtp.example.com";
        mailServer.username = "site-monitor@example.com";
        mailServer.password = "1234567899999";
        auto message = new EmailMessage();
       
        message.to ~= "touser@example.com";
        message.from = "site-monitor@example.com";
        message.subject = "验证码";
        message.setTextBody("ASDFGH");
        message.send(mailServer); // send via some relay    
        return "ok";
    }

参考arsd https://github.com/adamdruppe/arsd 将以下几个文件引入到项目扩展包

需要引入的核心类包括:characterencodings.d color.ddom.d,email.dhtmltotext.d

注意:mailServer.server 必须使用:smtps :例如smtps://smtp.example.com

Login to reply