public SendRawThread(EmailAddress envelopefrom, EmailAddress[] mailto, String rawtext, SmtpServer smtpserver, LogWindow logwindow) { this._envelopefrom=envelopefrom; this._mailto=mailto; this._rawtext=rawtext; this._smtpserver=smtpserver; this._logwindow=logwindow; }
/// <summary> /// Send the MAIL FROM command /// Throw a MailException if we can't connect. /// </summary> /// <param name="mailfrom">The Envelope-From address</param> /// <returns>the SMTP response</returns> public SmtpResponse MailFrom(EmailAddress mailfrom) { if (!_isConnected) { throw new MailException("The connection is closed."); } String message = "MAIL FROM: <"+mailfrom.Email+">"+SmtpProxy.ENDOFLINE; LogDebug("SENDING: "+message); Write(message); return ReadSmtpResponse(); }
public SendThread( EmailAddress fromaddress, EmailAddress[] toaddresses, EmailAddress envelopefrom, String subject, String htmlcontent, String textcontent, SmtpServer smtpserver, LogWindow logwindow) { _fromaddress=fromaddress; _toaddresses=toaddresses; _envelopefrom=envelopefrom; _subject=subject; _htmlcontent=htmlcontent; _textcontent=textcontent; _smtpserver=smtpserver; _logwindow=logwindow; }
public void TestSerialization() { EmailAddress emailaddress=new EmailAddress("*****@*****.**", "My Name"); Assert.AreEqual("My Name <*****@*****.**>",emailaddress.ToString()); emailaddress=new EmailAddress("*****@*****.**", "Last, First"); Assert.AreEqual("\"Last, First\" <*****@*****.**>",emailaddress.ToString()); emailaddress=new EmailAddress("*****@*****.**", "<First Last>"); Assert.AreEqual("\"<First Last>\" <*****@*****.**>",emailaddress.ToString()); emailaddress=new EmailAddress("*****@*****.**", "[First Last]"); Assert.AreEqual("\"[First Last]\" <*****@*****.**>",emailaddress.ToString()); emailaddress=new EmailAddress("*****@*****.**", "(First Last)"); Assert.AreEqual("\"(First Last)\" <*****@*****.**>",emailaddress.ToString()); emailaddress=new EmailAddress("*****@*****.**", "First \"NickName\" Last"); Assert.AreEqual("\"First \\\"NickName\\\" Last\" <*****@*****.**>",emailaddress.ToString()); }
/// <summary> /// Send the email. /// </summary> /// <param name="emailMessage">The completed message</param> /// <param name="rcpttocollection">A list of email addresses which /// are to be used in the RCPT TO SMTP communication</param> /// <param name="mailfrom">An email address for the MAIL FROM /// part of the SMTP protocol.</param> /// <exception cref="SmtpException">throws an SmtpException if there /// is an unexpected SMTP error number sent from the server.</exception> /// <exception cref="MailException">throws a MailException if there /// is a network problem, connection problem, or other issue.</exception> /// <returns></returns> internal bool Send(ISendableMessage emailMessage, EmailAddressCollection rcpttocollection, EmailAddress mailfrom) { //ISmtpNegotiator negotiator=_smtpserver.GetSmtpNegotiator(); ISmtpProxy smtpproxy = GetSmtpProxy(); //smtpproxy.CaptureSmtpConversation=CaptureSmtpConversation; SmtpResponse smtpResponse = smtpproxy.Open(); try { #region Connect if (smtpResponse.ResponseCode != 220) { throw smtpResponse.GetException(); } #endregion #region HELO / EHLO if (UseEhlo()) { EhloSmtpResponse esmtpResponse = smtpproxy.Ehlo(GetHeloHost()); if (esmtpResponse.ResponseCode != 250) { // TODO: FIX THIS throw new SmtpException(esmtpResponse.ResponseCode, esmtpResponse.Message); } // do SMTP AUTH if (this._authToken != null) { smtpResponse = _authToken.Negotiate(smtpproxy, esmtpResponse.GetAvailableAuthTypes()); if (smtpResponse.ResponseCode != 235) { throw smtpResponse.GetException(); } } } else { smtpResponse = smtpproxy.Helo(GetHeloHost()); if (smtpResponse.ResponseCode != 250) { throw smtpResponse.GetException(); } } #endregion #region MAIL FROM smtpResponse = smtpproxy.MailFrom(mailfrom); if (smtpResponse.ResponseCode != 250) { throw smtpResponse.GetException(); } #endregion #region RCPT TO foreach (EmailAddress rcpttoaddress in rcpttocollection) { smtpResponse = smtpproxy.RcptTo(rcpttoaddress); if (smtpResponse.ResponseCode != 250) { throw smtpResponse.GetException(); } } #endregion #region DATA smtpResponse = smtpproxy.Data(); if (smtpResponse.ResponseCode != 354) { throw smtpResponse.GetException(); } //smtpResponse=negotiator.WriteData(); String message = emailMessage.ToDataString(); if (message == null) { throw new MailException("The message content is null"); } /* * // START Test With Domain Keys * // (this would appear as an event callback if it works) * MailSigner mailsigner=new MailSigner(); * bool signed = mailsigner.signMail(message); * if (!signed) * { * throw new MailException("Error creating DomainKeys signature."); * } * message=mailsigner.signedHeader + message; * // END Test With Domain Keys */ // Send the data smtpResponse = smtpproxy.WriteData(message); if (smtpResponse.ResponseCode != 250) { throw smtpResponse.GetException(); } #endregion #region QUIT // QUIT smtpResponse = smtpproxy.Quit(); if (smtpResponse.ResponseCode != 221) { throw smtpResponse.GetException(); } #endregion } finally { smtpproxy.Close(); OnLogSmtpCompleted(this, "Connection Closed"); } return(true); }
/// <summary> /// Find the index of the EmailAddress in the collection /// </summary> /// <param name="value">The object to find.</param> /// <returns>The index, from 0, or -1 if not found.</returns> public int IndexOf( EmailAddress value ) { return( List.IndexOf( value ) ); }
/// <summary> /// Insert an EmailAddress into the collection at the /// specified index. /// </summary> /// <param name="index">The index, starting at zero.</param> /// <param name="emailaddress">The email address to add to the collection</param> public void Insert( int index, EmailAddress emailaddress ) { List.Insert( index, emailaddress ); }
/// <summary> /// Remove an address, if found, from the collection. /// </summary> /// <param name="emailaddress">The EmailAddress to remove</param> public void Remove( EmailAddress emailaddress ) { List.Remove( emailaddress ); }
/// <summary> /// Add an object to the collection /// </summary> /// <param name="emailaddress">The EmailAddress object to add</param> /// <returns></returns> public int Add( EmailAddress emailaddress ) { return( List.Add( emailaddress ) ); }
public void TestJapaneseHtmlAndTextQPEncoding() { //SmtpServer smtpserver=TestAddressHelper.GetSmtpServer(); System.Text.Encoding encoding=System.Text.Encoding.GetEncoding("Shift_JIS"); EmailAddress japanesefromaddress=new EmailAddress(TestAddressHelper.GetFromAddress().Email, "日本語", EncodingType.QuotedPrintable, encoding); EmailAddress japanesetoaddress=new EmailAddress(TestAddressHelper.GetToAddress().Email, "日本語", EncodingType.QuotedPrintable, encoding); EmailMessage emailmessage=new EmailMessage(); emailmessage.HeaderEncoding=DotNetOpenMail.Encoding.EncodingType.QuotedPrintable; System.Text.Encoding jencoding=System.Text.Encoding.GetEncoding("iso-2022-jp"); //emailmessage.HeaderCharSet=System.Text.Encoding.GetEncoding("Shift_JIS"); emailmessage.HeaderCharSet=jencoding; log.Debug("ENCODING IS "+jencoding.EncodingName); log.Debug("IN HEADER:"+jencoding.HeaderName); log.Debug("IN BODY:"+jencoding.BodyName); log.Debug("CODE PAGE:"+jencoding.CodePage); log.Debug("WebName:"+jencoding.WebName); log.Debug("WINDOWS CODE PAGE:"+jencoding.WindowsCodePage); emailmessage.FromAddress=japanesefromaddress; emailmessage.AddToAddress(japanesetoaddress); emailmessage.Subject="日本語 - Quoted Printable"; emailmessage.TextPart=new TextAttachment("東京、日本語"); //emailmessage.TextPart.CharSet+AD0AIg-Shift_JIS+ACIAOw- emailmessage.TextPart.CharSet=jencoding; emailmessage.TextPart.Encoding=DotNetOpenMail.Encoding.EncodingType.QuotedPrintable; emailmessage.HtmlPart=new HtmlAttachment("<html><body>東京、日本語</body></html>"); //emailmessage.HtmlPart.CharSet+AD0AIg-Shift_JIS+ACIAOw- emailmessage.HtmlPart.CharSet=jencoding; emailmessage.HtmlPart.Encoding=DotNetOpenMail.Encoding.EncodingType.QuotedPrintable; emailmessage.Send(_smtpserver); String content=emailmessage.ToDataString(); StringReader sr=new StringReader(content); log.Debug(content); int i=0; String line=null; bool toHeaderEncoded=false; bool fromHeaderEncoded=false; bool subjectHeaderEncoded=false; bool htmlEncoded=false; bool textEncoded=false; bool hasPlainText=false; bool hasHtmlText=false; while ((line=sr.ReadLine())!=null) { i++; //log.Debug("FOUND +ACIAKw-line); if (line.IndexOf("To: =?iso-2022-jp?Q?=93=FA=96{=8C=EA?= <"+japanesetoaddress.Email+">")==0) { toHeaderEncoded=true; } if (line.IndexOf("From") == 0) { String expectedfrom="From: =?iso-2022-jp?Q?=93=FA=96{=8C=EA?= <"+japanesefromaddress.Email+">"; if (line.IndexOf(expectedfrom)== 0) { fromHeaderEncoded=true; } } if (line.IndexOf("Subject: =?iso-2022-jp?Q?=1B$BF|K\\8l=1B(B=20-=20Quoted=20Printable?=")==0) { subjectHeaderEncoded=true; } if (line.IndexOf("<html><body>=1B$BEl5~!\"F|K\\8l=1B(B</body></html>")==0) { //<html><body>=67=71=4E=AC=30=01=65=E5=67=2C=8A=9E</body></html> htmlEncoded=true; } if (line.IndexOf("=1B$BEl5~!\"F|K\\8l=1B(B")==0) { textEncoded=true; } if (line.IndexOf("Content-Type: text/plain")==0) { hasPlainText=true; } if (line.IndexOf("Content-Type: text/html")==0) { hasHtmlText=true; } if (line.IndexOf("X-Mailer: DotNetOpenMail " + VersionInfo.GetInstance().ToString())==0) { //hasDefaultXMailerHeader=true; } if (line.IndexOf("X-MyHeader1: my header number one") == 0) { //hasCustomHeader1=true; } if (line.IndexOf("X-MyHeader2: my header number two") == 0) { //hasCustomHeader2=true; } // log.Debug("Line +ACIAKw-i+-": +ACIAKw-line); } Assert.IsTrue(toHeaderEncoded, "To Header not encoded"); Assert.IsTrue(fromHeaderEncoded, "From Header not encoded"); Assert.IsTrue(subjectHeaderEncoded, "Subject Header not encoded"); //Assert.IsTrue(hasSubjectHeader, "Missing Subject Header"); //Assert.IsTrue(hasMimeVersion, "Missing Mime Version header"); //Assert.IsTrue(hasMultipartAlternative, "Missing Mime Multipart/Alternative setting"); Assert.IsTrue(hasPlainText, "Missing Plain Text"); Assert.IsTrue(hasHtmlText, "Missing HTML"); Assert.IsTrue(htmlEncoded, "HTML Not encoded"); Assert.IsTrue(textEncoded, "Text Not encoded"); //Assert.IsTrue(hasDefaultXMailerHeader, "Missing X-Mailer Header"); //Assert.IsTrue(hasCustomHeader1, "Missing Custom Header 1"); //Assert.IsTrue(hasCustomHeader2, "Missing Custom Header 2"); //Assert.AreEqual(2, quotedPrintableParts, "Expected 2 quoted printable declarations, found +ACIAKw-quotedPrintableParts); }
/// <summary> /// Send the email. /// </summary> /// <param name="emailMessage">The completed message</param> /// <param name="rcpttocollection">A list of email addresses which /// are to be used in the RCPT TO SMTP communication</param> /// <param name="mailfrom">An email address for the MAIL FROM /// part of the SMTP protocol.</param> /// <exception cref="SmtpException">throws an SmtpException if there /// is an unexpected SMTP error number sent from the server.</exception> /// <exception cref="MailException">throws a MailException if there /// is a network problem, connection problem, or other issue.</exception> /// <returns></returns> internal bool Send(ISendableMessage emailMessage, EmailAddressCollection rcpttocollection, EmailAddress mailfrom) { //ISmtpNegotiator negotiator=_smtpserver.GetSmtpNegotiator(); ISmtpProxy smtpproxy=GetSmtpProxy(); //smtpproxy.CaptureSmtpConversation=CaptureSmtpConversation; SmtpResponse smtpResponse=smtpproxy.Open(); try { #region Connect if (smtpResponse.ResponseCode!=220) { throw smtpResponse.GetException(); } #endregion #region HELO / EHLO if (UseEhlo()) { EhloSmtpResponse esmtpResponse=smtpproxy.Ehlo(GetHeloHost()); if (esmtpResponse.ResponseCode!=250) { // TODO: FIX THIS throw new SmtpException(esmtpResponse.ResponseCode, esmtpResponse.Message); } // do SMTP AUTH if (this._authToken!=null) { smtpResponse=_authToken.Negotiate(smtpproxy, esmtpResponse.GetAvailableAuthTypes()); if (smtpResponse.ResponseCode!=235) { throw smtpResponse.GetException(); } } } else { smtpResponse=smtpproxy.Helo(GetHeloHost()); if (smtpResponse.ResponseCode!=250) { throw smtpResponse.GetException(); } } #endregion #region MAIL FROM smtpResponse=smtpproxy.MailFrom(mailfrom); if (smtpResponse.ResponseCode!=250) { throw smtpResponse.GetException(); } #endregion #region RCPT TO foreach ( EmailAddress rcpttoaddress in rcpttocollection) { smtpResponse=smtpproxy.RcptTo(rcpttoaddress); if (smtpResponse.ResponseCode!=250) { throw smtpResponse.GetException(); } } #endregion #region DATA smtpResponse=smtpproxy.Data(); if (smtpResponse.ResponseCode!=354) { throw smtpResponse.GetException(); } //smtpResponse=negotiator.WriteData(); String message=emailMessage.ToDataString(); if (message==null) { throw new MailException("The message content is null"); } /* // START Test With Domain Keys // (this would appear as an event callback if it works) MailSigner mailsigner=new MailSigner(); bool signed = mailsigner.signMail(message); if (!signed) { throw new MailException("Error creating DomainKeys signature."); } message=mailsigner.signedHeader + message; // END Test With Domain Keys */ // Send the data smtpResponse=smtpproxy.WriteData(message); if (smtpResponse.ResponseCode!=250) { throw smtpResponse.GetException(); } #endregion #region QUIT // QUIT smtpResponse=smtpproxy.Quit(); if (smtpResponse.ResponseCode!=221) { throw smtpResponse.GetException(); } #endregion } finally { smtpproxy.Close(); OnLogSmtpCompleted(this, "Connection Closed"); } return true; }
/// <summary> /// Send the MAIL FROM command /// Throw a MailException if we can't connect. /// </summary> /// <param name="rcpttoaddress">A recipient's address</param> /// <returns>the SMTP response</returns> public SmtpResponse RcptTo(EmailAddress rcpttoaddress) { if (!_isConnected) { throw new MailException("The connection is closed."); } String message= "RCPT TO: <"+rcpttoaddress.Email+">"+SmtpProxy.ENDOFLINE; LogDebug("SENDING: "+message); Write(message); return ReadSmtpResponse(); }
public SmtpResponse MailFrom(EmailAddress rcptto) { throw new ApplicationException("MailFrom Not implemented yet"); }
/// <summary> /// Add a To address to the Headers. This will also /// be used during the "RCPT TO" SMTP negotiation /// </summary> /// <param name="emailaddress">Email Address object of the recipient</param> public void AddToAddress(EmailAddress emailaddress) { _toaddresses.Add(emailaddress); }
/// <summary> /// Add a Cc address to the Headers. This will also /// be used during the "RCPT TO" SMTP negotiation /// </summary> /// <param name="emailaddress">Email Address object of the recipient</param> public void AddCcAddress(EmailAddress emailaddress) { _ccaddresses.Add(emailaddress); }
/// <summary> /// Add a recipient who will be "Blind Carbon Copied" /// as a recipient of the email. BCC addresses are /// not added to the email headers, but only appear /// during the "RCPT TO" SMTP negotiation. /// </summary> /// <param name="emailaddress">The EmailAddress object</param> public void AddBccAddress(EmailAddress emailaddress) { _bccaddresses.Add(emailaddress); }
/// <summary> /// Add a recipient to the EmailAddressCollection /// of recipients /// </summary> /// <param name="emailaddress"></param> public void AddRcptToAddress(EmailAddress emailaddress) { _rcpttoaddresses.Add(emailaddress); }
/// <summary> /// Add a recipient to the EmailAddressCollection /// of recipients /// </summary> /// <param name="emailaddress"></param> public void AddRcptToAddress(EmailAddress emailaddress) { _rcpttoaddresses.Add(emailaddress); }
public SmtpResponse RcptTo(EmailAddress rcptto) { throw new ApplicationException("RcptTo Not implemented yet"); }
public void TestJapaneseHtmlAndTextB64Encoding() { //SmtpServer smtpserver=TestAddressHelper.GetSmtpServer(); System.Text.Encoding encoding=System.Text.Encoding.GetEncoding("Shift_JIS"); EmailAddress japanesefromaddress=new EmailAddress(TestAddressHelper.GetFromAddress().Email, "日本語", EncodingType.Base64, encoding); EmailAddress japanesetoaddress=new EmailAddress(TestAddressHelper.GetToAddress().Email, "日本語", EncodingType.Base64, encoding); EmailMessage emailmessage=new EmailMessage(); emailmessage.HeaderEncoding=DotNetOpenMail.Encoding.EncodingType.Base64; emailmessage.HeaderCharSet=System.Text.Encoding.GetEncoding("Shift_JIS"); emailmessage.FromAddress=japanesefromaddress; emailmessage.AddToAddress(japanesetoaddress); emailmessage.Subject="日本語 - Base 64"; emailmessage.TextPart=new TextAttachment("東京、日本語"); emailmessage.TextPart.CharSet=System.Text.Encoding.GetEncoding("Shift_JIS"); emailmessage.TextPart.Encoding=DotNetOpenMail.Encoding.EncodingType.Base64; emailmessage.HtmlPart=new HtmlAttachment("<html><body>東京、日本語</body></html>"); emailmessage.HtmlPart.CharSet=System.Text.Encoding.GetEncoding("Shift_JIS"); emailmessage.HtmlPart.Encoding=DotNetOpenMail.Encoding.EncodingType.Base64; emailmessage.Send(_smtpserver); String content=emailmessage.ToDataString(); StringReader sr=new StringReader(content); log.Debug(content); int i=0; String line=null; bool toHeaderEncoded=false; bool fromHeaderEncoded=false; bool subjectHeaderEncoded=false; //bool htmlEncoded=false; //bool textEncoded=false; bool hasPlainText=false; bool hasHtmlText=false; while ((line=sr.ReadLine())!=null) { i++; //log.Debug("FOUND +ACIAKw-line); if (line.IndexOf("To: =?iso-2022-jp?B?k/qWe4zq?= <"+japanesetoaddress.Email+">")==0) { toHeaderEncoded=true; } if (line.IndexOf("From") == 0) { String expectedfrom="From: =?iso-2022-jp?B?k/qWe4zq?= <"+japanesefromaddress.Email+">"; if (line.IndexOf(expectedfrom)== 0) { fromHeaderEncoded=true; } } if (line.IndexOf("Subject: =?iso-2022-jp?B?k/qWe4zqIC0gQmFzZSA2NA==?=")==0) { subjectHeaderEncoded=true; } if (line.IndexOf("Content-Type: multipart/alternative")==0) { //htmlEncoded=true; } if (line.IndexOf("Content-Type: text/html")==0) { hasHtmlText=true; } if (line.IndexOf("Content-Type: text/plain")==0) { hasPlainText=true; } if (line.IndexOf("X-Mailer: DotNetOpenMail " + VersionInfo.GetInstance().ToString())==0) { //hasDefaultXMailerHeader=true; } if (line.IndexOf("X-MyHeader1: my header number one") == 0) { //hasCustomHeader1=true; } if (line.IndexOf("X-MyHeader2: my header number two") == 0) { //hasCustomHeader2=true; } // log.Debug("Line +ACIAKw-i+-": +ACIAKw-line); } Assert.IsTrue(toHeaderEncoded, "To Header not encoded"); Assert.IsTrue(fromHeaderEncoded, "From Header not encoded"); Assert.IsTrue(subjectHeaderEncoded, "Subject Header not encoded"); //Assert.IsTrue(hasSubjectHeader, "Missing Subject Header"); //Assert.IsTrue(hasMimeVersion, "Missing Mime Version header"); //Assert.IsTrue(hasMultipartAlternative, "Missing Mime Multipart/Alternative setting"); Assert.IsTrue(hasPlainText, "Missing Plain Text"); Assert.IsTrue(hasHtmlText, "Missing HTML"); //Assert.IsTrue(htmlEncoded, "HTML Not encoded"); //Assert.IsTrue(textEncoded, "Text Not encoded"); //Assert.IsTrue(hasDefaultXMailerHeader, "Missing X-Mailer Header"); //Assert.IsTrue(hasCustomHeader1, "Missing Custom Header 1"); //Assert.IsTrue(hasCustomHeader2, "Missing Custom Header 2"); //Assert.AreEqual(2, quotedPrintableParts, "Expected 2 quoted printable declarations, found +ACIAKw-quotedPrintableParts); }