Ejemplo n.º 1
0
 public static void SendMail(MailMessage mail)
 {
     try
     {
         using (var smtpClient = new SmtpClient())
         {
             smtpClient.Send(mail);
         }
     }
     catch (Exception e)
     {
         using (var ctx = new dsSPDDataContext())
         {
             MailError em = new MailError();
             em.ErrorId      = Guid.NewGuid().ToString();
             em.Body         = mail.Body;
             em.EmailTo      = mail.To.FirstOrDefault().Address;
             em.Subject      = mail.Subject;
             em.Status       = false;
             em.ErrorMessage = e.Message + "||" + e.InnerException;
             em.ErrorDate    = DateTime.Now;
             ctx.MailErrors.InsertOnSubmit(em);
             ctx.SubmitChanges();
         }
     }
 }
Ejemplo n.º 2
0
            public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
            {
                StringStream      text           = trigger.Text;
                string            str            = text.NextModifiers();
                List <ItemRecord> itemRecordList = new List <ItemRecord>();
                uint cod   = 0;
                uint money = 0;

                if (str.Contains("i"))
                {
                    ItemTemplate template = ItemMgr.GetTemplate(trigger.Text.NextEnum(Asda2ItemId.None));
                    if (template == null)
                    {
                        trigger.Reply("Invalid ItemId.");
                        return;
                    }

                    ItemRecord record = ItemRecord.CreateRecord(template);
                    itemRecordList.Add(record);
                    record.SaveLater();
                }

                if (str.Contains("c"))
                {
                    cod = text.NextUInt();
                }
                string recipientName = trigger.Text.NextWord();

                if (recipientName.Length == 0)
                {
                    trigger.Reply("Could not send mail - Unknown Recipient: " + recipientName);
                }
                else
                {
                    string    subject   = trigger.Text.NextWord(",");
                    string    remainder = trigger.Text.Remainder;
                    MailError mailError = MailMgr.SendMail(recipientName, subject, remainder, MailStationary.GM,
                                                           itemRecordList, money, cod, trigger.Args.User);
                    if (mailError == MailError.OK)
                    {
                        trigger.Reply("Done.");
                    }
                    else
                    {
                        trigger.Reply("Could not send mail: " + mailError);
                    }
                }
            }
Ejemplo n.º 3
0
        public static bool SendMail(IEnumerable <string> toAddress, string subject, string body, MailError error, Attachment fileAttachment = null)
        {
            SmtpClient smtpClient = new SmtpClient(smtpServer, smtpPort)
            {
                Credentials = new NetworkCredential(fromAddress, password),
                EnableSsl   = true
            };
            MailMessage mailMessage = new MailMessage();

            //Add recipient address
            foreach (var address in toAddress)
            {
                mailMessage.To.Add(address);
            }

            mailMessage.From    = new MailAddress(fromAddress);
            mailMessage.Subject = subject;
            mailMessage.Body    = body;

            if (fileAttachment != null)
            {
                //Adds attachment to the file
                mailMessage.Attachments.Add(fileAttachment);
            }

            //try and send the mail
            try
            {
                smtpClient.Send(mailMessage);

                return(true);
            }
            catch (Exception ex)
            {
                error(ex.Message);
                return(false);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Sends a responce detailing the results of the client's mail request.
 /// </summary>
 public static void SendResult(IPacketReceiver client, uint mailId, MailResult result, MailError err, uint itemId, int itemCount)
 {
     using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_SEND_MAIL_RESULT, 12 + 4 + 4))
     {
         packet.Write(mailId);
         packet.Write((uint)result);
         packet.Write((uint)err);
         packet.Write(itemId);
         packet.Write(itemCount);
         client.Send(packet, addEnd: false);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Sends a responce detailing the results of the client's mail request.
 /// </summary>
 public static void SendResult(IPacketReceiver client, uint mailId, MailResult result, MailError err,
                               InventoryError invErr)
 {
     using (RealmPacketOut packet = new RealmPacketOut((PacketId)RealmServerOpCode.SMSG_SEND_MAIL_RESULT, 16))
     {
         packet.Write(mailId);
         packet.Write((uint)result);
         packet.Write((uint)err);
         packet.Write((uint)invErr);
         client.Send(packet, false);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Sends a responce detailing the results of the client's mail request.
 /// </summary>
 public static void SendResult(IPacketReceiver client, uint mailId, MailResult result, MailError err, uint itemId, int itemCount)
 {
     using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_SEND_MAIL_RESULT, 12 + 4 + 4))
     {
         packet.Write(mailId);
         packet.Write((uint)result);
         packet.Write((uint)err);
         packet.Write(itemId);
         packet.Write(itemCount);
         client.Send(packet);
     }
 }