public void Start() { var registry = new ExtensionRegistry(); //registry.AddRequiredExtension(new JsonExtension()); if (MessagesPerAck == 1) { registry.AddRequiredExtension(new SingleAckExtension()); } else if (MessagesPerAck != 0) { registry.AddRequiredExtension(new BatchAckExtension { MessagesPerAck = MessagesPerAck, MaxAmountOfPendingMessages = 1000000, AckExpireTime = TimeSpan.FromSeconds(120) // as we queue up msgs a lot faster than they can be sent. }); } registry.AddRequiredExtension(new DotNetTypeExtension()); var parts = RemoteHost.Split(':'); var port = int.Parse(parts[1]); _client = new SharpMessagingClient("TestClient", registry); _client.Start(parts[0], port); _client.FrameReceived = OnTimingFrame; //start timing var buffer = Encoding.ASCII.GetBytes(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.ffff")); _client.Send(new MessageFrame(buffer)); Console.WriteLine("All enqueued"); }
/// <summary> /// The SendMail method attempts to send the email. /// </summary> /// <returns>True or False /// /// Example: /// /// if Mailer.SendMail then /// /// Response.Write "Mail sent..." /// /// else /// /// Response.Write "Mail failure. Check mail host server name and tcp/ip connection..." /// /// end if</returns> public bool SendMail() { try { if (PGPPath != null) { Process p = new Process { StartInfo = { CreateNoWindow = true, FileName = PGPPath, Arguments = PGPParams } }; p.Start(); } MailMessage msg = new MailMessage(); msg.Body = BodyText; if (CustomCharSet != null) { msg.BodyEncoding = System.Text.Encoding.GetEncoding(CustomCharSet); } else { switch (CharSet) { case 1: //us ascci msg.BodyEncoding = System.Text.Encoding.ASCII; break; case 2: //iso-8859-1 msg.BodyEncoding = System.Text.Encoding.GetEncoding("iso-8859-1"); break; } } msg.IsBodyHtml = ContentType == "text/html"; if (ConfirmRead) { msg.Headers.Add("Disposition-Notification-To", "<" + FromAddress + ">"); } if (this.DateTime != null) { msg.Headers.Add("Date", this.DateTime); } if (Organization != null) { msg.Headers.Add("Organization", Organization); } msg.Sender = new MailAddress(FromAddress, FromName); msg.From = msg.Sender; foreach (var addr in recipients) { msg.To.Add(addr); } foreach (var addr in ccs) { msg.CC.Add(addr); } foreach (var addr in bccs) { msg.Bcc.Add(addr); } foreach (var filename in attachments) { Attachment data = new Attachment(filename); // Add time stamp information for the file. ContentDisposition disposition = data.ContentDisposition; disposition.CreationDate = File.GetCreationTime(filename); disposition.ModificationDate = File.GetLastWriteTime(filename); disposition.ReadDate = File.GetLastAccessTime(filename); msg.Attachments.Add(data); } foreach (var header in headers) { msg.Headers.Add(header.Split(new string[] { ": " }, StringSplitOptions.None)[0], header.Split(new string[] { ": " }, StringSplitOptions.None)[1]); } switch (Priority) { case 1: msg.Priority = MailPriority.High; break; case 3: msg.Priority = MailPriority.Normal; break; case 5: msg.Priority = MailPriority.Low; break; } if (ReplyTo != null) { msg.ReplyTo = new MailAddress(ReplyTo); } if (ReturnReceipt) { msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.Delay; } msg.Subject = Subject; SmtpClient smtp = new SmtpClient(); smtp.Timeout = TimeOut; foreach (string server in RemoteHost.Split(';')) { if (server.IndexOf(':') != -1) { smtp.Host = server.Split(':')[0]; smtp.Port = Int32.Parse(server.Split(':')[1]); } else { smtp.Host = server; } try { smtp.Send(msg); return(true); } catch (Exception ex) { Response = ex.Message; } } } catch (Exception ex) { Response = ex.Message; } return(false); }