Package voxo.server.actions

Source Code of voxo.server.actions.SendEmailAction

package voxo.server.actions;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.SQLException;

import javax.mail.MessagingException;

import voxo.common.entities.Packet;
import voxo.common.entities.User;
import voxo.common.enums.EnumPacket;
import voxo.common.packets.ChatPacket;
import voxo.server.Messages;
import voxo.server.exceptions.RequestException;
import voxo.server.managers.UserManager;
import voxo.server.services.MailService;
import voxo.server.services.NetworkService;

public class SendEmailAction {
  public SendEmailAction(InetAddress ip, ChatPacket cp) throws SQLException, RequestException, MessagingException, UnknownHostException, IOException {
    User to = UserManager.searchUserAbsolute(new User(null, cp.getTo(), null, null, null, null, null)).get(0);
    User from = UserManager.searchUserAbsolute(new User(null, cp.getUsername(), null, null, null, null, null)).get(0);
    if (to == null) {
      throw new RequestException();
    }
    if (from == null) {
      throw new RequestException(Messages.getString("ContactAddAction.ERR_UserNotFound")); //$NON-NLS-1$
    }
    MailService.sendMail(from.getEmail(), from.getUsername(), to.getEmail(), to.getUsername(), String.format(Messages.getString("SendEmailAction.MailSubject"), from.getUsername()), String.format(Messages.getString("SendEmailAction.MailBody"), cp.getTxtMsg())); //$NON-NLS-1$ //$NON-NLS-2$
    NetworkService.sendPacket(ip, new Packet(EnumPacket.SERVER_Notice, Messages.getString("SendEmailAction.MailSentResponce"))); //$NON-NLS-1$
  }
}
TOP

Related Classes of voxo.server.actions.SendEmailAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.