/// <summary>
/// Creates undelivered warning for user and places it to relay folder.
/// </summary>
/// <param name="relayInfo">Relay info</param>
/// <param name="error">SMTP returned error text.</param>
/// <param name="file">Messsage file.</param>
private void MakeUndeliveredWarning(RelayInfo relayInfo,string error,Stream file)
{
try
{
// If sender isn't specified, we can't send warning to sender.
// Just skip warning sending.
if(relayInfo.From.Length == 0){
return;
}
file.Position = relayInfo.MessageStartPos;
// Make new message
MimeConstructor mime = new MimeConstructor();
mime.From = "postmaster";
mime.To = new string[]{relayInfo.From};
mime.Subject = "Undelivered mail warning";
mime.Attachments.Add(new Attachment("data.eml",file));
string bodyTxt = Relay.UndelWarningTemplate;
bodyTxt = bodyTxt.Replace("<#RECEPTIENT>",relayInfo.To);
bodyTxt = bodyTxt.Replace("<#ERROR>",error);
bodyTxt = bodyTxt.Replace("<#UNDELIVERED_HOURS>",relayInfo.DeviveringForHours.ToString());
mime.Body = bodyTxt;
byte[] data = System.Text.Encoding.Default.GetBytes(mime.ConstructMime());
using(MemoryStream strm = new MemoryStream(data)){
m_pServer.ProcessAndStoreMessage("",new string[]{relayInfo.From},strm);
}
// byte[] data = System.Text.Encoding.Default.GetBytes(mime.ConstructMime());
// MailStore.StoreMessage("",new MemoryStream(data),relayInfo.From,"",true);
}
catch(Exception x)
{
Error.DumpError(x,new System.Diagnostics.StackTrace());
}
}