public static void setEnvelopeHeaderSMTPMessage(SimpleSMTPHeader header, String references, String messageid, String inreplyto, bool isAnswer, String myMessageId, DateTime dtSent) { try { header.addHeaderField("X-Mailer", "ARAConsultoriaySoluciones.com"); header.addHeaderField("Date", InternalDateformat(dtSent)); header.addHeaderField("Message-ID", myMessageId); if (isAnswer) { if (references == null || references.Length == 0) { references = inreplyto; } if (messageid != null && messageid.Length > 0) { references = messageid; } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("setEnvelopeHeaderSMTPMessage Exception:" + e.ToString()); } }
public static String fillDraftEmailGmailApi(Base64OutputStream baos, SimpleSMTPHeader header, String msgId, DateTime dt, string to, string subject, string body, bool nota) { String transferencoding = "7BIT"; try { String references = null; setEnvelopeHeaderSMTPMessage(header, references, msgId, null, false, msgId, dt); byte[] bytes = createHtmlEmail(subject, false, nota); //int encoding = Utility.checkAscii(bytes); //if (encoding == Utility.ALL_ASCII) //{ // transferencoding = "7BIT"; //} //else if (encoding == Utility.MOSTLY_ASCII) //{ transferencoding = "quoted-printable"; //bytes = Utility.encodeQP(bytes); //} //else //{ // bytes = Base64.encode(bytes, Base64.DEFAULT); // transferencoding = "base64"; //} //String boundary = null; header.addHeaderField("Content-Type", "text/html" + "; charset=\"utf-8\""); header.addHeaderField("Content-Transfer-Encoding", transferencoding);//"quoted-printable"); String[] _to = to.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries); if (_to != null) { foreach (String recpt in _to) { if (recpt.Trim().Length > 0) { header.addTO(recpt); } } } header.isAppend(true); if (baos != null) { Utility.writeBytes(baos, header.toString()); } header.clearHeaders(); if (bytes != null) { if (baos != null) { baos.Write(bytes, 0, bytes.Length); } bytes = null; } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("FILL EMAL HEADERS" + e.ToString()); } return(transferencoding); }
public static String fillEmailGmailApi(Stream baos, SimpleSMTPHeader header, ref String boundary, String msgId, DateTime dt, string to, string subject, DateTime fechaCorte) { String transferencoding = "7BIT"; try { string references = null; setEnvelopeHeaderSMTPMessage(header, references, msgId, null, false, msgId, dt); byte[] bytes = createHtmlEmail(subject, false, fechaCorte); int encoding = Utility.checkAscii(bytes); if (encoding == Utility.ALL_ASCII) { transferencoding = "7BIT"; } else if (encoding == Utility.MOSTLY_ASCII) { transferencoding = "quoted-printable"; bytes = Utility.encodeQP(bytes); } else { bytes = Base64.encode(bytes, Base64.DEFAULT); transferencoding = "base64"; } boundary = GenerateBoundary();// generateBoundary(); header.addHeaderField("Content-Type", "multipart/mixed; boundary=\"----" + boundary + "\""); String[] _to = to.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries); if (_to != null) { foreach (String recpt in _to) { if (recpt.Trim().Length > 0) { header.addTO(recpt); } } } header.isAppend(true); if (baos != null) { byte[] b = Encoding.UTF8.GetBytes(header.toString()); baos.Write(b, 0, b.Length); b = null; } header.clearHeaders(); header.addBoundaryField(boundary); header.addHeaderField("Content-Type", "text/html; charset=\"utf-8\""); header.addHeaderField("Content-Transfer-Encoding", transferencoding); if (baos != null) { byte[] bytesAppend = Encoding.UTF8.GetBytes(header.headerMultiparttoString());//.getBytes("UTF-8"); baos.Write(bytesAppend, 0, bytesAppend.Length); bytesAppend = null; } if (bytes != null) { if (baos != null) { baos.Write(bytes, 0, bytes.Length); } bytes = null; } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("FILL EMAL HEADERS" + e.ToString()); } return(transferencoding); }
private static bool getPostDataEmailOperations(Stream s, string msgId, string boundary, string to, string subject, DateTime fecha, string pathPDF) { if (subject != null && subject.Length > 0) { subject = Utility.encodeSubjectText(subject); } SimpleSMTPHeader sheader = new SimpleSMTPHeader(Global.getEmailPublicoGeneral(), subject); Utility.writeBytes(s, "--" + boundary + "\r\n"); Utility.writeBytes(s, "Content-Type: application/json; charset=UTF-8\r\n\r\n"); Utility.writeBytes(s, "{\r\n}\r\n\r\n"); Utility.writeBytes(s, "--" + boundary + "\r\n"); Utility.writeBytes(s, "Content-Type: message/rfc822\r\n\r\n"); string boundaryEmail = string.Empty; DateTime dt = DateTime.Now; fillEmailGmailApi(s, sheader, ref boundaryEmail, msgId, dt, to, subject, fecha); byte[] buffer = null; Base64.Coder coder = null; try { string[] files = new string[1]; files[0] = pathPDF; int read = 0; for (int i = 0; i < 1; i++) { FileInfo info = new FileInfo(files[i]); coder = new Base64.Encoder(Base64.CRLF | Base64.NO_CLOSE, null); s.Write(CRLF, 0, CRLF.Length); Utility.writeBytes(s, "------" + boundaryEmail + "\r\n"); Utility.writeBytes(s, "Content-Type: application/octet-stream\r\n"); Utility.writeBytes(s, "Content-Transfer-Encoding: base64\r\n"); Utility.writeBytes(s, "Content-Disposition: attachment; filename=\"" + Utility.encodeText(info.Name) + "\"\r\n\r\n"); buffer = new byte[8192]; read = 0; using (FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read)) { while ((read = fs.Read(buffer, 0, 8192)) > 0) { if (read >= 8192) { coder.process(buffer, 0, read, false, s); } else { coder.process(buffer, 0, read, true, s); } } fs.Dispose(); } s.Write(CRLF, 0, CRLF.Length); coder = null; info = null; } buffer = new byte[8192]; read = 0; coder = new Base64.Encoder(Base64.CRLF | Base64.NO_CLOSE, null); s.Write(CRLF, 0, CRLF.Length); Utility.writeBytes(s, "------" + boundaryEmail + "\r\n"); Utility.writeBytes(s, "Content-Type: image/png\r\n"); Utility.writeBytes(s, "Content-Transfer-Encoding: base64\r\n"); Utility.writeBytes(s, "Content-Disposition: inline; filename=\"" + Utility.encodeText("recyclame.png") + "\"\r\n"); Utility.writeBytes(s, "Content-ID: <logo>\r\n\r\n"); using (var img = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Recyclame.Resources.recyclame.fw.jpeg")) { using (BinaryReader reader = new BinaryReader(img)) { while ((read = reader.Read(buffer, 0, 8192)) > 0) { coder.process(buffer, 0, read, false, s); } reader.Dispose(); } } s.Write(CRLF, 0, CRLF.Length); coder = null; Utility.writeBytes(s, "------" + boundaryEmail + "--\r\n"); Utility.writeBytes(s, "--" + boundary + "--\r\n"); s.Flush(); return(true); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("EMAIL OPERATION POST DATA EXCEPTION: " + e.ToString()); } return(false); }