Esempio n. 1
0
        /// <summary>
        /// Sends a customizable email to the address of your choosing.
        /// </summary>
        /// <param name="from">What node the email should come from</param>
        /// <param name="to">What email address to send the email too, doesn't support domain names, just IPs. ([email protected])</param>
        /// <param name="body">The body of the email</param>
        /// <returns></returns>
        public static bool SendCustomEmail(Node from, string to, string body) {
            string[] emailArgs = to.Split('@');
            Node mailServer = Server.Instance.GetComputerManager().GetNodeByIp(emailArgs[1]);
            MailMessage message = new MailMessage(to, from.GetDisplayName() + "@" + from.ip, body);
            MailDaemon mailDaemon = (MailDaemon)mailServer.GetDaemon("mail");

            return mailDaemon != null ? mailDaemon.ReceiveMail(message) : false;
        }
Esempio n. 2
0
        /// <summary>
        /// Sends a password reset email to the specified user at the specified server, and outputs the result as well as the auth code.
        /// </summary>
        /// <param name="from">What node the password email should come from</param>
        /// <param name="to">What email address to send the email too, doesn't support domain names, just IPs. ([email protected])</param>
        /// <param name="username">The username of the account that needs it's password to be reset</param>
        /// <returns></returns>
        public static bool SendPasswordResetEmail(Node from, string to, string username) {
            if (CheckPassResetExpire(from, username))
                return false;
            _authRequests.Add(new PassResetRequest(from, username, out int authCode));
            string[] emailArgs = to.Split('@');
            Node mailServer = Server.Instance.GetComputerManager().GetNodeByIp(emailArgs[1]);
            MailMessage message = new MailMessage(emailArgs[0], from.GetDisplayName() + "@" + from.ip, $"Attention {emailArgs[0]}! You or someone with access to your account at {from.ip} has requested a password reset!\nIf this was not you or someone you know has access to this account, please disregard this email.\nHowever, if you requested your password to be reset, the authentication code is {authCode}.");
            MailDaemon mailDaemon = (MailDaemon)mailServer.GetDaemon("mail");

            return mailDaemon != null ? mailDaemon.ReceiveMail(message) : false;
        }