本文整理汇总了C#中ActiveUp.Net.Mail.Message.ToMimeString方法的典型用法代码示例。如果您正苦于以下问题:C# Message.ToMimeString方法的具体用法?C# Message.ToMimeString怎么用?C# Message.ToMimeString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveUp.Net.Mail.Message
的用法示例。
在下文中一共展示了Message.ToMimeString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
/// <summary>
/// Sends the message using the specified host as mail exchange server.
/// </summary>
/// <param name="message">The message to be sent.</param>
/// <param name="servers">Servers to be used to send the message (in preference order).</param>
/// <example>
/// <code>
/// C#
///
/// Message message = new Message();
/// message.Subject = "Test";
/// message.From = new Address("[email protected]","John Doe");
/// message.To.Add("[email protected]","Mike Johns");
/// message.BodyText.Text = "Hello this is a test!";
///
/// ServerCollection servers = new ServerCollection();
/// servers.Add("mail.myhost.com",25);
/// servers.Add("mail2.myhost.com",25);
///
/// SmtpClient.Send(message,servers);
///
/// VB.NET
///
/// Dim message As New Message
/// message.Subject = "Test"
/// message.From = New Address("[email protected]","John Doe")
/// message.To.Add("[email protected]","Mike Johns")
/// message.BodyText.Text = "Hello this is a test!"
///
/// Dim servers As New ServerCollection
/// servers.Add("mail.myhost.com",25)
/// servers.Add("mail2.myhost.com",25)
///
/// SmtpClient.Send(message,servers)
///
/// JScript.NET
///
/// var message:Message = new Message();
/// message.Subject = "Test";
/// message.From = new Address("[email protected]","John Doe");
/// message.To.Add("[email protected]","Mike Johns");
/// message.BodyText.Text = "Hello this is a test!";
///
/// var servers:ServerCollection = new ServerCollection();
/// servers.Add("mail.myhost.com",25);
/// servers.Add("mail2.myhost.com",25);
///
/// SmtpClient.Send(message,servers);
/// </code>
/// </example>
public static bool Send(Message message, ServerCollection servers, out string serverMessage)
{
// Ensure that the mime part tree is built
message.CheckBuiltMimePartTree();
serverMessage = string.Empty;
ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
bool messageSent = false;
for(int i=0;i<servers.Count;i++)
{
try
{
if (servers[i].ServerEncryptionType != EncryptionType.None)
{
#if !PocketPC
smtp.ConnectSsl(servers[i].Host,servers[i].Port);
#else
smtp.Connect(servers[i].Host, servers[i].Port);
#endif
}else {
smtp.Connect(servers[i].Host,servers[i].Port);
}
try
{
smtp.Ehlo(System.Net.Dns.GetHostName());
}
catch
{
smtp.Helo(System.Net.Dns.GetHostName());
}
if(servers[i].Username!=null && servers[i].Username.Length>0 && servers[i].Password!=null && servers[i].Password.Length>0) smtp.Authenticate(servers[i].Username,servers[i].Password,SaslMechanism.Login);
if(message.From.Email!=string.Empty) smtp.MailFrom(message.From);
else smtp.MailFrom(message.Sender);
smtp.RcptTo(message.To);
smtp.RcptTo(message.Cc);
smtp.RcptTo(message.Bcc);
serverMessage = smtp.Data(message.ToMimeString());//,(message.Charset!=null ? message.Charset : "iso-8859-1"));
smtp.Disconnect();
messageSent = true;
break;
}
catch
{
continue;
}
}
return messageSent;
}
示例2: SendSsl
public static bool SendSsl(Message message, string server, int port)
{
// Ensure that the mime part tree is built
message.CheckBuiltMimePartTree();
ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
smtp.ConnectSsl(server, port);
try
{
smtp.Ehlo(System.Net.Dns.GetHostName());
}
catch
{
smtp.Helo(System.Net.Dns.GetHostName());
}
if (message.From.Email != string.Empty) smtp.MailFrom(message.From);
else smtp.MailFrom(message.Sender);
smtp.RcptTo(message.To);
smtp.RcptTo(message.Cc);
smtp.RcptTo(message.Bcc);
smtp.Data(message.ToMimeString());//,(message.Charset!=null ? message.Charset : "iso-8859-1"));
smtp.Disconnect();
return true;
}
示例3: Append
/// <summary>
/// Appends the provided message to the mailbox.
/// </summary>
/// <param name="message">The message to be appended.</param>
/// <param name="flags">Flags to be set for the message.</param>
/// <param name="dateTime">The internal date to be set for the message.</param>
/// <example>
/// <code>
/// C#
///
/// Message message = new Message();
/// message.From = new Address("[email protected]","John Doe");
/// message.To.Add("[email protected]","Mike Johns");
/// message.Subject = "hey!";
/// message.Attachments.Add("C:\\myfile.doc");
/// message.HtmlBody.Text = "As promised, the requested document.<br /><br />Regards,<br>John.";
///
/// FlagCollection flags = new FlagCollection();
/// flags.Add("Read");
///
/// Imap4Client imap = new Imap4Client();
/// Mailbox inbox = imap.SelectMailbox("Read Messages");
/// inbox.Append(message,flags,System.DateTime.Now);
/// imap.Disconnect();
///
/// VB.NET
///
/// Dim message As New Message
/// message.From = new Address("[email protected]","John Doe")
/// message.To.Add("[email protected]","Mike Johns")
/// message.Subject = "hey!"
/// message.Attachments.Add("C:\myfile.doc")
/// message.HtmlBody.Text = "As promised, the requested document.<br /><br />Regards,<br>John."
///
/// Dim flags As New FlagCollection
/// flags.Add("Read")
///
/// Dim imap As New Imap4Client
/// Dim inbox As Mailbox = imap.SelectMailbox("Read Messages")
/// inbox.Append(message,flags,System.DateTime.Now)
/// imap.Disconnect()
///
/// JScript.NET
///
/// var message:Message = new Message();
/// message.From = new Address("[email protected]","John Doe")
/// message.To.Add("[email protected]","Mike Johns");
/// message.Subject = "hey!";
/// message.Attachments.Add("C:\\myfile.doc");
/// message.HtmlBody.Text = "As promised, the requested document.<br /><br />Regards,<br>John."
///
/// var flags:FlagCollection = new FlagCollection();
/// flags.Add("Read");
///
/// var imap:Imap4Client = new Imap4Client();
/// var inbox:Mailbox = imap.SelectMailbox("Read Messages");
/// inbox.Append(message,flags,System.DateTime.Now);
/// imap.Disconnect();
/// </code>
/// </example>
public string Append(Message message, IFlagCollection flags, DateTime dateTime)
{
return this.Append(message.ToMimeString(),flags,dateTime);
}
示例4: DirectSend
/// <summary>
/// Sends the message using the specified DNS servers to get mail exchange servers addresses.
/// </summary>
/// <param name="message">The message to be sent.</param>
/// <param name="dnsServers">Servers to be used (in preference order).</param>
/// <example>
/// <code>
/// C#
///
/// Message message = new Message();
/// message.Subject = "Test";
/// message.From = new Address("[email protected]","John Doe");
/// message.To.Add("[email protected]","Mike Johns");
/// message.BodyText.Text = "Hello this is a test!";
///
/// ServerCollection servers = new ServerCollection();
/// servers.Add("ns1.dnsserver.com",53);
/// servers.Add("ns2.dnsserver.com",53);
///
/// SmtpClient.DirectSend(message,servers);
///
/// VB.NET
///
/// Dim message As New Message
/// message.Subject = "Test"
/// message.From = New Address("[email protected]","John Doe")
/// message.To.Add("[email protected]","Mike Johns")
/// message.BodyText.Text = "Hello this is a test!"
///
/// Dim servers As New ServerCollection
/// servers.Add("ns1.dnsserver.com",53)
/// servers.Add("ns2.dnsserver.com",53)
///
/// SmtpClient.DirectSend(message,servers)
///
/// JScript.NET
///
/// var message:Message = new Message();
/// message.Subject = "Test";
/// message.From = new Address("[email protected]","John Doe");
/// message.To.Add("[email protected]","Mike Johns");
/// message.BodyText.Text = "Hello this is a test!";
///
/// var servers:ServerCollection = new ServerCollection();
/// servers.Add("ns1.dnsserver.com",53);
/// servers.Add("ns2.dnsserver.com",53);
///
/// SmtpClient.DirectSend(message,servers);
/// </code>
/// </example>
public static string DirectSend(Message message, ServerCollection dnsServers)
{
// Ensure that the mime part tree is built
message.CheckBuiltMimePartTree();
string email = (message.From.Name!="(unknown)") ? message.From.Email : message.Sender.Email;
int recipientCount = message.To.Count+message.Cc.Count+message.Bcc.Count;
#if !PocketPC
System.Array domains = System.Array.CreateInstance(typeof(string),new int[] {recipientCount},new int[] {0});
System.Array adds = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address),new int[] {recipientCount},new int[] {0});
#else
System.Array domains = System.Array.CreateInstance(typeof(string), new int[] { recipientCount });
System.Array adds = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address), new int[] { recipientCount });
#endif
ActiveUp.Net.Mail.AddressCollection recipients = new ActiveUp.Net.Mail.AddressCollection();
recipients += message.To;
recipients += message.Cc;
recipients += message.Bcc;
for(int i=0;i<recipients.Count;i++)
{
if (ActiveUp.Net.Mail.Validator.ValidateSyntax(recipients[i].Email))
{
domains.SetValue(recipients[i].Email.Split('@')[1],i);
adds.SetValue(recipients[i],i);
}
}
System.Array.Sort(domains,adds,null);
string currentDomain = "";
string address = "";
string buf = "";
ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
for(int j=0;j<adds.Length;j++)
{
address = ((ActiveUp.Net.Mail.Address)adds.GetValue(j)).Email;
if(((string)domains.GetValue(j))==currentDomain)
{
smtp.RcptTo(address);
if(j==(adds.Length-1))
{
smtp.Data(message.ToMimeString(true));//,(message.Charset!=null ? message.Charset : "iso-8859-1"));
smtp.Disconnect();
}
}
else
{
if(currentDomain!="")
{
smtp.Data(message.ToMimeString(true));//,(message.Charset!=null ? message.Charset : "iso-8859-1"));
smtp.Disconnect();
smtp = new ActiveUp.Net.Mail.SmtpClient();
//.........这里部分代码省略.........
示例5: ToMimeMessage
public Message ToMimeMessage(int tenant, string user, bool loadAttachments)
{
var mimeMessage = new Message
{
Date = DateTime.UtcNow,
From = new Address(From, string.IsNullOrEmpty(DisplayName) ? "" : Codec.RFC2047Encode(DisplayName))
};
if (Important)
mimeMessage.Priority = MessagePriority.High;
mimeMessage.To.AddRange(To.ConvertAll(address =>
{
var addr = Parser.ParseAddress(address);
addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
return new Address(addr.Email, addr.Name);
}));
mimeMessage.Cc.AddRange(Cc.ConvertAll(address =>
{
var addr = Parser.ParseAddress(address);
addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
return new Address(addr.Email, addr.Name);
}));
mimeMessage.Bcc.AddRange(Bcc.ConvertAll(address =>
{
var addr = Parser.ParseAddress(address);
addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
return new Address(addr.Email, addr.Name);
}));
mimeMessage.Subject = Codec.RFC2047Encode(Subject);
// Set correct body
if (Attachments.Any() || AttachmentsEmbedded.Any())
{
foreach (var attachment in Attachments)
{
attachment.user = user;
attachment.tenant = tenant;
var attach = CreateAttachment(attachment, loadAttachments);
if (attach != null)
mimeMessage.Attachments.Add(attach);
}
foreach (var embeddedAttachment in AttachmentsEmbedded)
{
embeddedAttachment.user = user;
embeddedAttachment.tenant = tenant;
var attach = CreateAttachment(embeddedAttachment, true);
if (attach != null)
mimeMessage.EmbeddedObjects.Add(attach);
}
}
mimeMessage.MessageId = MimeMessageId;
mimeMessage.InReplyTo = MimeReplyToId;
mimeMessage.BodyText.Charset = Encoding.UTF8.HeaderName;
mimeMessage.BodyText.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
mimeMessage.BodyText.Text = "";
mimeMessage.BodyHtml.Charset = Encoding.UTF8.HeaderName;
mimeMessage.BodyHtml.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
mimeMessage.BodyHtml.Text = HtmlBody;
mimeMessage.OriginalData = Encoding.GetEncoding("iso-8859-1").GetBytes(mimeMessage.ToMimeString());
return mimeMessage;
}
示例6: SendMessageWithAuthentication
private void SendMessageWithAuthentication(string username, string password,
SaslMechanism mechanism, Message message)
{
Authenticate(username, password, mechanism);
if (message.From.Email != string.Empty) MailFrom(message.From);
else MailFrom(message.Sender);
RcptTo(message.To);
RcptTo(message.Cc);
RcptTo(message.Bcc);
Data(message.ToMimeString());
Disconnect();
}
示例7: SendMessageWithAuthentication
private static void SendMessageWithAuthentication(SmtpClient smtp, string username, string password,
SaslMechanism mechanism, Message message)
{
smtp.Authenticate(username, password, mechanism);
if (message.From.Email != string.Empty) smtp.MailFrom(message.From);
else smtp.MailFrom(message.Sender);
smtp.RcptTo(message.To);
smtp.RcptTo(message.Cc);
smtp.RcptTo(message.Bcc);
smtp.Data(message.ToMimeString());
smtp.Disconnect();
}
示例8: SendMessageWith
private void SendMessageWith(Message message)
{
if (message.From.Email != string.Empty) MailFrom(message.From);
else MailFrom(message.Sender);
RcptTo(message.To);
RcptTo(message.Cc);
RcptTo(message.Bcc);
Data(message.ToMimeString()); //,(message.Charset!=null ? message.Charset : "iso-8859-1"));
Disconnect();
}
示例9: Send
/// <summary>
/// Sends the message using the specified host as mail exchange server on the specified port.
/// </summary>
/// <param name="message">The message to be sent.</param>
/// <param name="host">The host to be used.</param>
/// <param name="port">The port to be used.</param>
/// <example>
/// <code>
/// C#
///
/// Message message = new Message();
/// message.Subject = "Test";
/// message.From = new Address("[email protected]","John Doe");
/// message.To.Add("[email protected]","Mike Johns");
/// message.BodyText.Text = "Hello this is a test!";
///
/// SmtpClient.Send(message,"mail.myhost.com",8504);
///
/// VB.NET
///
/// Dim message As New Message
/// message.Subject = "Test"
/// message.From = New Address("[email protected]","John Doe")
/// message.To.Add("[email protected]","Mike Johns")
/// message.BodyText.Text = "Hello this is a test!"
///
/// SmtpClient.Send(message,"mail.myhost.com",8504)
///
/// JScript.NET
///
/// var message:Message = new Message();
/// message.Subject = "Test";
/// message.From = new Address("[email protected]","John Doe");
/// message.To.Add("[email protected]","Mike Johns");
/// message.BodyText.Text = "Hello this is a test!";
///
/// SmtpClient.Send(message,"mail.myhost.com",8504);
/// </code>
/// </example>
public bool Send(Message message, string host, int port)
{
// Ensure that the mime part tree is built
message.CheckBuiltMimePartTree();
ConnectPlain(host, port);
try
{
Ehlo(System.Net.Dns.GetHostName());
}
catch
{
Helo(System.Net.Dns.GetHostName());
}
if (message.From.Email != string.Empty) MailFrom(message.From);
else MailFrom(message.Sender);
RcptTo(message.To);
RcptTo(message.Cc);
RcptTo(message.Bcc);
Data(message.ToMimeString());
Disconnect();
return true;
}
示例10: Send
//.........这里部分代码省略.........
//message.Headers.Add("x-sender-ip\uFFFD", Request.ServerVariables["REMOTE_ADDR\uFFFD"]);
string[] sArr5 = System.IO.Directory.GetFiles(Page.Server.MapPath(Application["writedirectory\uFFFD"].ToString()));
for (int i3 = 0; i3 < sArr5.Length; i3++)
{
string s4 = sArr5[i3];
if (s4.IndexOf("\\temp\\\uFFFD" + Session.SessionID + "_Attach_\uFFFD") != -1)
{
ActiveUp.Net.Mail.MimePart attachment = new ActiveUp.Net.Mail.MimePart(s4, true);
attachment.Filename = s4.Substring(s4.IndexOf("_Attach_\uFFFD") + 8);
attachment.ContentName = s4.Substring(s4.IndexOf("_Attach_\uFFFD") + 8);
message.Attachments.Add(attachment);
}
}
message.From = new ActiveUp.Net.Mail.Address(iFromEmail.Text, iFromName.Text);
if (((System.Web.UI.HtmlControls.HtmlInputButton)sender).ID == "iSubmit\uFFFD")
{
try
{
message.Send((string)Application["smtpserver\uFFFD"], System.Convert.ToInt32(Application["smtpport\uFFFD"]), (string)Application["user\uFFFD"], (string)Application["password\uFFFD"], ActiveUp.Net.Mail.SaslMechanism.CramMd5);
}
catch
{
try
{
message.Send((string)Application["smtpserver\uFFFD"], System.Convert.ToInt32(Application["smtpport\uFFFD"]), (string)Application["user\uFFFD"], (string)Application["password\uFFFD"], ActiveUp.Net.Mail.SaslMechanism.CramMd5);
}
catch
{
message.Send((string)Application["smtpserver\uFFFD"], System.Convert.ToInt32(Application["smtpport\uFFFD"]));
}
}
try
{
if (iAction.Value == "r\uFFFD")
{
ActiveUp.Net.Mail.Mailbox mailbox1 = ((ActiveUp.Net.Mail.Imap4Client)Session["imapobject\uFFFD"]).SelectMailbox(MailboxName);
ActiveUp.Net.Mail.FlagCollection flagCollection = new ActiveUp.Net.Mail.FlagCollection();
flagCollection.Add("Answered\uFFFD");
if (mailbox1.Fetch.Flags(MessageId).Merged.ToLower().IndexOf("\\answered\uFFFD") == -1)
mailbox1.AddFlagsSilent(MessageId, flagCollection);
}
lConfirm.Text = ((Language)Session["language\uFFFD"]).Words[32].ToString() + " : <br /><br />\uFFFD" + message.To.Merged + message.Cc.Merged + message.Bcc.Merged.Replace(";\uFFFD", "<br />\uFFFD");
pForm.Visible = false;
pConfirm.Visible = true;
System.Web.HttpCookie httpCookie1 = new System.Web.HttpCookie("fromname\uFFFD", iFromName.Text);
System.Web.HttpCookie httpCookie2 = new System.Web.HttpCookie("fromemail\uFFFD", iFromEmail.Text);
System.Web.HttpCookie httpCookie3 = new System.Web.HttpCookie("replyto\uFFFD", iReplyTo.Text);
System.DateTime dateTime1 = System.DateTime.Now;
httpCookie1.Expires = dateTime1.AddMonths(2);
System.DateTime dateTime2 = System.DateTime.Now;
httpCookie2.Expires = dateTime2.AddMonths(2);
System.DateTime dateTime3 = System.DateTime.Now;
httpCookie3.Expires = dateTime3.AddMonths(2);
Response.Cookies.Add(httpCookie1);
Response.Cookies.Add(httpCookie2);
Response.Cookies.Add(httpCookie3);
if (cSave.Checked)
{
System.Web.HttpCookie httpCookie4 = new System.Web.HttpCookie("folder\uFFFD", dBoxes.SelectedItem.Text);
System.DateTime dateTime4 = System.DateTime.Now;
httpCookie4.Expires = dateTime4.AddMonths(2);
Response.Cookies.Add(httpCookie4);
ActiveUp.Net.Mail.Mailbox mailbox2 = ((ActiveUp.Net.Mail.Imap4Client)Session["imapobject\uFFFD"]).SelectMailbox(dBoxes.SelectedItem.Text);
mailbox2.Append(message.ToMimeString());
}
string[] sArr6 = System.IO.Directory.GetFiles(Page.Server.MapPath(Application["writedirectory\uFFFD"].ToString()));
for (int i4 = 0; i4 < sArr6.Length; i4++)
{
string s5 = sArr6[i4];
if (s5.IndexOf(Session.SessionID) != -1)
System.IO.File.Delete(s5);
}
}
catch (System.Exception e1)
{
Page.RegisterStartupScript("ShowError\uFFFD", "<script>ShowErrorDialog('\uFFFD" + ((Language)Session["language\uFFFD"]).Words[83].ToString() + "','\uFFFD" + System.Text.RegularExpressions.Regex.Escape(e1.Message + e1.StackTrace).Replace("'\uFFFD", "\\'\uFFFD") + "');</script>\uFFFD");
}
}
else
{
System.Web.HttpCookie httpCookie5 = new System.Web.HttpCookie("folder\uFFFD", dBoxes.SelectedItem.Text);
System.DateTime dateTime5 = System.DateTime.Now;
httpCookie5.Expires = dateTime5.AddMonths(2);
Response.Cookies.Add(httpCookie5);
ActiveUp.Net.Mail.Mailbox mailbox3 = ((ActiveUp.Net.Mail.Imap4Client)Session["imapobject\uFFFD"]).SelectMailbox(dBoxes.SelectedItem.Text);
mailbox3.Append(message.ToMimeString());
}
string[] sArr8 = System.IO.Directory.GetFiles(Page.Server.MapPath(Application["writedirectory\uFFFD"].ToString()));
for (int i5 = 0; i5 < sArr8.Length; i5++)
{
string s6 = sArr8[i5];
if (s6.IndexOf(Session.SessionID) != -1)
System.IO.File.Delete(s6);
}
}
catch (System.Exception e2)
{
Page.RegisterStartupScript("ShowError\uFFFD", "<script>ShowErrorDialog('\uFFFD" + ((Language)Session["language\uFFFD"]).Words[82].ToString() + "','\uFFFD" + System.Text.RegularExpressions.Regex.Escape(e2.Message + e2.StackTrace).Replace("'\uFFFD", "\\'\uFFFD") + "');</script>\uFFFD");
}
}
示例11: QueryServer
/// <summary>
/// Queries the server.
/// </summary>
/// <param name="host">The host.</param>
/// <param name="port">The port.</param>
/// <param name="message">The message.</param>
/// <param name="filename">The filename.</param>
/// <returns></returns>
private static CtchResponse QueryServer(string host, int port, Message message, string filename)
{
bool reference = true;
if (message != null)
reference = false;
else
message = Parser.ParseMessageFromFile(filename);
string version = "0000001";
// Prepare the commtouch headers
string content = string.Format("X-CTCH-PVer: {0}\r\nX-CTCH-MailFrom: {1}\r\nX-CTCH-SenderIP: {2}\r\n", version, message.Sender.Email, message.SenderIP);
if (reference)
{
content += string.Format("X-CTCH-FileName: {0}\r\n", filename);
}
else
{
content += string.Format("\r\n{0}", message.ToMimeString());
}
// Prepare the request with HTTP header
string request = string.Format("POST /ctasd/{0} HTTP/1.0\r\nContent-Length: {1}\r\n\r\n", (reference ? "ClassifyMessage_File" : "ClassifyMessage_Inline"), content.Length)
+ content;
//try
//{
TcpClient client = new TcpClient();
client.Connect(host, port);
Byte[] data = System.Text.Encoding.ASCII.GetBytes(request);
// Stream stream = client.GetStream();
NetworkStream stream = client.GetStream();
// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);
#if DEBUG
Console.WriteLine("<requestSent>");
Console.WriteLine("{0}", request);
Console.WriteLine("</requestSent>");
#endif
// Receive the TcpServer.response.
// Buffer to store the response bytes.
data = new Byte[256];
// String to store the response ASCII representation.
String responseData = String.Empty;
// Read the first batch of the TcpServer response bytes.
Int32 bytes = stream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
#if DEBUG
Console.WriteLine("<responseReceived>");
Console.WriteLine("{0}", responseData);
Console.WriteLine("</responseReceived>");
#endif
CtchResponse ctchResponse = CtchResponse.ParseFromString(responseData);
#if DEBUG
Console.WriteLine(ctchResponse.ToString());
#endif
// Close everything.
stream.Close();
client.Close();
//}
//catch (ArgumentNullException e)
//{
// Console.WriteLine("ArgumentNullException: {0}", e);
//}
//catch (SocketException e)
//{
// Console.WriteLine("SocketException: {0}", e);
//}
return ctchResponse;
}
示例12: Send
/// <summary>
/// Sends the message using the specified host on the specified port. Secure SASL Authentication is performed according to the requested mechanism.
/// </summary>
/// <param name="message">The message to be sent.</param>
/// <param name="host">The host to be used.</param>
/// <param name="username">The username to be used for authentication.</param>
/// <param name="password">The password to be used for authentication.</param>
/// <param name="mechanism">SASL Mechanism to be used for authentication.</param>
/// <param name="port">The port to be used.</param>
/// <example>
/// <code>
/// C#
///
/// Message message = new Message();
/// message.Subject = "Test";
/// message.From = new Address("[email protected]","John Doe");
/// message.To.Add("[email protected]","Mike Johns");
/// message.BodyText.Text = "Hello this is a test!";
///
/// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504);
///
/// VB.NET
///
/// Dim message As New Message
/// message.Subject = "Test"
/// message.From = New Address("[email protected]","John Doe")
/// message.To.Add("[email protected]","Mike Johns")
/// message.BodyText.Text = "Hello this is a test!"
///
/// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504)
///
/// JScript.NET
///
/// var message:Message = new Message();
/// message.Subject = "Test";
/// message.From = new Address("[email protected]","John Doe");
/// message.To.Add("[email protected]","Mike Johns");
/// message.BodyText.Text = "Hello this is a test!";
///
/// SmtpClient.Send(message,"mail.myhost.com","jdoe1234","tanstaaf",SaslMechanism.CramMd5,8504);
/// </code>
/// </example>
public static bool Send(Message message, string host, int port, string username, string password, SaslMechanism mechanism)
{
// Ensure that the mime part tree is built
message.CheckBuiltMimePartTree();
var smtp = new SmtpClient();
smtp.Connect(host,port);
smtp.SendEhloHelo();
smtp.Authenticate(username, password, mechanism);
if(message.From.Email!=string.Empty) smtp.MailFrom(message.From);
else smtp.MailFrom(message.Sender);
smtp.RcptTo(message.To);
smtp.RcptTo(message.Cc);
smtp.RcptTo(message.Bcc);
smtp.Data(message.ToMimeString());
smtp.Disconnect();
return true;
}
示例13: Post
/// <summary>
/// Posts the provided article.
/// </summary>
/// <param name="article">The article data as a string.</param>
/// <returns>The server's response.</returns>
/// <example>
/// <code>
/// C#
///
/// Message article = new Message();
/// article.HeaderFields.Add("NewsGroups","myhost.info");
/// article.From = new Address("[email protected]","John Doe");
/// article.Subject = "Test";
/// article.Body = "Hello this is a test !";
/// NntpClient nttp = new NntpClient();
/// nntp.Connect("news.myhost.com");
/// if(nntp.PostingAllowed) nntp.Post(article);
/// else throw new NntpException("Posting not allowed. Couldn't post.");
/// nntp.Disconnect();
///
/// VB.NET
///
/// Dim article as New Message
/// article.HeaderFields.Add("NewsGroups","myhost.info")
/// article.From = New Address("[email protected]","John Doe")
/// article.Subject = "Test"
/// article.Body = "Hello this is a test !"
/// Dim nttp as New NntpClient()
/// nntp.Connect("news.myhost.com")
/// If nntp.PostingAllowed Then
/// nntp.Post(article)
/// Else
/// Throw New NntpException("Posting not allowed. Couldn't post.")
/// End If
/// nntp.Disconnect()
///
/// JScript.NET
///
/// var article:Message = new Message();
/// article.HeaderFields.Add("NewsGroups","myhost.info");
/// article.From = new Address("[email protected]","John Doe");
/// article.Subject = "Test";
/// article.Body = "Hello this is a test !";
/// var nntp:NntpClient = new NntpClient();
/// nntp.Connect("news.myhost.com");
/// if(nntp.PostingAllowed) nntp.Post(article);
/// else throw new NntpException("Posting not allowed. Couldn't post.");
/// nntp.Disconnect();
/// </code>
/// </example>
public string Post(Message article)
{
return this.Post(article.ToMimeString());
}
示例14: SendMessageWith
private static void SendMessageWith(SmtpClient smtp, Message message)
{
if (message.From.Email != string.Empty) smtp.MailFrom(message.From);
else smtp.MailFrom(message.Sender);
smtp.RcptTo(message.To);
smtp.RcptTo(message.Cc);
smtp.RcptTo(message.Bcc);
smtp.Data(message.ToMimeString());//,(message.Charset!=null ? message.Charset : "iso-8859-1"));
smtp.Disconnect();
}