Beispiel #1
0
        public async Task SendEmailAndFailure(
            string senderEmail,
            string senderNickname,
            HatoMessage msg,
            List <IGrouping <string, string> > allTargetEmails)
        {
            var failedSendChannels = await SendEmail(msg, allTargetEmails);

            if (failedSendChannels.Count > 0)
            {
                string strippedBody;
                if (msg.BodyPlain.Length > maxBodyLength)
                {
                    strippedBody = msg.BodyPlain.Substring(0, 200) + "...";
                }
                else
                {
                    strippedBody = msg.BodyPlain;
                }

                foreach ((var name, var reason) in failedSendChannels)
                {
                    await SendFailureEmailBack(
                        senderEmail,
                        senderNickname,
                        name,
                        strippedBody,
                        reason,
                        msg.Timestamp);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add a message to a specific channel. The message's original ID will be overridden.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="channelId"></param>
        /// <returns></returns>
        public async Task <Ulid> SaveMessageIntoChannel(HatoMessage message, Ulid channelId)
        {
            if (message.MsgId == Ulid.Empty)
            {
                message.MsgId = Ulid.NewUlid();
            }
            if (channelId != Ulid.Empty)
            {
                message.ChannelId = channelId;
            }

            await db.Messages.AddAsync(message);

            await db.SaveChangesAsync();

            return(message.MsgId);
        }
Beispiel #3
0
        public EmailData HatoMessageToEmailDataPartial(HatoMessage msg)
        {
            var data = new EmailData();

            data.FromAddress = new Address(
                $"{msg._Channel?.ChannelUsername ?? msg.ChannelId.ToString()}@{recv.Domain}",
                msg._Channel?.ChannelTitle);
            data.Subject = msg.Title;

            if (msg.BodyHtml != null)
            {
                data.IsHtml = true;
                data.Body   = msg.BodyHtml;
                data.PlaintextAlternativeBody = msg.BodyPlain;
            }
            else
            {
                data.IsHtml = false;
                data.Body   = msg.BodyPlain;
                data.PlaintextAlternativeBody = null;
            }
            return(data);
        }
Beispiel #4
0
 public async Task <Ulid> SaveMessageIntoChannel(HatoMessage message)
 {
     return(await SaveMessageIntoChannel(message, Ulid.Empty));
 }