public void FixtureSetUp () { fname = Path.GetTempFileName (); using (FileStream fs = File.OpenWrite (fname)) { fs.WriteByte (0); fs.Close (); } attachment = new MailAttachment (fname); }
public static bool SendEmail11(string pGmailEmail, string pTo, string pSubject, string pBody, string cc, string pAttachmentPath) { try { pGmailEmail = "*****@*****.**"; SmtpClient SmtpServer = new SmtpClient(); MailMessage mail = new MailMessage(); System.Text.StringBuilder mailbody = new System.Text.StringBuilder(); //SmtpServer.Port = 25; //SmtpServer.Host = "86.96.198.37"; //SmtpServer.Credentials = new NetworkCredential("86.96.198.37\\admissions", "Mark205"); //SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network; SmtpServer.Port = 587; SmtpServer.Host = "smtp.office365.com"; SmtpServer.Credentials = new NetworkCredential("smtp.office365.com\\[email protected]", "Mark205"); SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network; SmtpServer.EnableSsl = true; mail.From = new MailAddress(pGmailEmail); mail.To.Add(pTo); mail.Subject = pSubject; if (cc != "") { mail.CC.Add(cc); } mail.IsBodyHtml = true; mailbody.Append(pBody); if (pAttachmentPath.Trim() != "") { try { System.Web.Mail.MailAttachment MyAttachment = new System.Web.Mail.MailAttachment(pAttachmentPath); //mail.Attachments.Add(MyAttachment); //mail.Priority = System.Web.Mail.MailPriority.High; } catch { } } mail.Body = mailbody.ToString(); // SmtpServer.Send(mail); return(true); } catch (Exception ex) { return(false); } }
/// <summary> /// 发送带附件的Email /// </summary> /// <param name="accessories">附件文件的物理地址</param> private static void SendEmailWithAccessories(string accessories, string content) { System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage(); System.Web.Mail.MailAttachment attachment = new System.Web.Mail.MailAttachment(accessories); //定义一个附件 message.Attachments.Add(attachment); message.BodyFormat = System.Web.Mail.MailFormat.Html; message.From = Configuration.EventLogAddresser; message.To = Configuration.EventLogAddressee; message.Cc = ""; message.Bcc = ""; message.Subject = "系统日志定期扫描报告"; message.Body = content; System.Web.Mail.SmtpMail.Send(message); }
public bool SendMail(List<string> mailIds, string subject, string body, List<string> attachmentFilePaths) { try { var myMailMessage = new MailMessage(); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com"); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465"); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2"); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //Use 0 for anonymous myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", PGmailAccount); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", PGmailPassword); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMailMessage.From = PGmailAccount; if (mailIds != null && mailIds.Count > 0) { string toMails = mailIds.Aggregate(string.Empty, (current, mailid) => current + (mailid + ";")); toMails = toMails.Substring(0, toMails.Length - 1); myMailMessage.To = toMails; myMailMessage.Subject = subject; var pFormat = new MailFormat(); pFormat = MailFormat.Html; myMailMessage.BodyFormat = pFormat; myMailMessage.Body = body; //string pAttachmentPath = "//servername/filename"; //contains the path of the attachment (if any) //if (pAttachmentPath.Trim() != "") //{ // MailAttachment MyEmailAttachment = new MailAttachment(pAttachmentPath); // myMailMessage.Attachments.Add(MyEmailAttachment); // myMailMessage.Priority = MailPriority.High; //} if (attachmentFilePaths != null && attachmentFilePaths.Count > 0) { foreach (string attachmentFilePath in attachmentFilePaths) { var attachment = new MailAttachment(attachmentFilePath); myMailMessage.Attachments.Add(attachment); } } myMailMessage.Priority = MailPriority.High; SmtpMail.SmtpServer = "smtp.gmail.com:465"; SmtpMail.Send(myMailMessage); } return true; } catch (Exception) { return false; } }
public void EnviaCorreo(String From, String To, String Subject, String Mensaje, String sFile, String sFile2, String SmtpServer, int port, String username, String passwor, String NombreReceptor, String NombreEmisor) { try { MailMessage omsg = new MailMessage(); omsg.From = From; omsg.To = To; MailAttachment oarch = new MailAttachment(sFile, MailEncoding.Base64); omsg.Attachments.Add(oarch); if (false == string.IsNullOrEmpty(sFile2)) { MailAttachment oarch2 = new MailAttachment(sFile2, MailEncoding.Base64); omsg.Attachments.Add(oarch2); } omsg.Body = NombreReceptor + "\r\n" + "\r\n" + Mensaje.Replace(@"\r\n", "\r\n") + "\r\n" + "\r\n" + NombreEmisor + "\r\n" + "\r\n" + "Esta factura fue emitida por InvoiceONE" + "\r\n" + "Visítanos en www.invoiceone.com.mx" + "\r\n" + "*****@*****.**"; omsg.Subject = Subject; omsg.BodyFormat = MailFormat.Text; if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(passwor)) { if (ConfigurationSettings.AppSettings["enableSsl"].ToString().Trim() == "true") omsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); else omsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "0"); omsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username); omsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", passwor); } omsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", port.ToString()); SmtpMail.SmtpServer = SmtpServer; SmtpMail.Send(omsg); } catch (Exception ex) { throw ex; } }
public bool SendMessage(string srcMail, string destMail, string srcText, string subject, bool isHtml, string filename) { if (destMail.Length > 0) { MailMessage m = new MailMessage(); m.From = srcMail; m.To = destMail; m.Subject = subject; m.Body = srcText; m.BodyFormat = isHtml ? MailFormat.Html : MailFormat.Text; m.BodyEncoding = Encoding.GetEncoding("windows-1251"); if (filename.Length > 3 && File.Exists(filename)) { MailAttachment mailAttachment = new MailAttachment(filename); m.Attachments.Add(mailAttachment); } SmtpMail.SmtpServer = "robots.1gb.ru"; SmtpMail.Send(m); /* System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage(srcMail, destMail, subject, srcText); MyMailMessage.IsBodyHtml = isHtml; System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential(srcMail, "Do67qat!"); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.yandex.ru", 587); mailClient.EnableSsl = true; if(filename.Length > 3 && File.Exists(filename)) { //MailAttachment mailAttachment = new MailAttachment(filename); System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(filename, System.Net.Mime.MediaTypeNames.Application.Octet); MyMailMessage.Attachments.Add(data); } mailClient.UseDefaultCredentials = false; mailClient.Credentials = mailAuthentication; mailClient.Send(MyMailMessage); */ return true; } return false; }
/// <summary> /// Function to Send email with attachment /// </summary> /// <param name="To"></param> /// <param name="From"></param> /// <param name="Subject"></param> /// <param name="path"></param> /// <param name="CC"></param> public void SendMail(string To, string From, string CC, string BCC, string Subject, string Body, string Attachpath) { // // Variable Declarations // string _bodyMessage = Body; // // Create a Mail Message object // System.Web.Mail.MailMessage EmailMessage = new System.Web.Mail.MailMessage(); SmtpMail.SmtpServer = smtpServer; // // Assigning To,From,CC address to mail // EmailMessage.To = To; EmailMessage.From = From; EmailMessage.Cc = CC; EmailMessage.BodyFormat = MailFormat.Html; // // Subject line of the Email // EmailMessage.Subject = Subject; // // Body of the Email // EmailMessage.Body = _bodyMessage; // // Attaching the files from given path // System.Web.Mail.MailAttachment myAttachment = new System.Web.Mail.MailAttachment(Attachpath); EmailMessage.Attachments.Add(myAttachment); // // Send the message // System.Web.Mail.SmtpMail.Send(EmailMessage); }
public void SendAttachmentEmail() { try { Cursor.Current = Cursors.WaitCursor; MailMessage mailMsg = new MailMessage(); mailMsg.From = "*****@*****.**"; mailMsg.To = "*****@*****.**"; mailMsg.Subject = txtMailId.Text.Trim()+ "--" + txtSubjest.Text.Trim(); mailMsg.BodyFormat = MailFormat.Text; mailMsg.Body = txtBody.Text; foreach (string strPath in lstbxAttach.Items) { MailAttachment attach = new MailAttachment(strPath); mailMsg.Attachments.Add(attach); } mailMsg.Priority = MailPriority.High; SmtpMail.SmtpServer = "smtp.gmail.com";//smtp is :smtp.gmail.com // SmtpMail.SmtpServer = "plus.smtp.mail.yahoo.com";//smtp is :smtp.yahoo.com mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "*****@*****.**"); mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "openmiracleOpensource"); // - smtp.gmail.com use port 465 or 587 // - plus.smtp.mail.yahoo.com use port 465 or 587 mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465"); mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); SmtpMail.Send(mailMsg); Cursor.Current = Cursors.Default; isSend = true; isCheck = true; MessageBox.Show("Mail sent successfully ", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception) { Cursor.Current = Cursors.Default; isSend = true; MessageBox.Show("Mail sending failed", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void AttachFiles(MailMessage mail, Project project, string filesetID) { if (StringUtils.IsNullOrEmpty(filesetID)) { return; } // lookup fileset FileSet fileset = project.DataTypeReferences[filesetID] as FileSet; if (fileset == null) { Console.Error.WriteLine("[MailLogger] Fileset \"{0}\" is not" + " defined. No files have been attached.", filesetID); return; } foreach (string fileName in fileset.FileNames) { if (!File.Exists(fileName)) { Console.Error.WriteLine("[MailLogger] Attachment \"{0}\"" + " does not exist. Skipping.", filesetID); continue; } // create attachment MailAttachment attachment = new MailAttachment(fileName, MailEncoding.UUEncode); // add attachment to mail mail.Attachments.Add(attachment); } }
public void emailLog() { MailMessage objMailMessage = new MailMessage(); objMailMessage.Body = "Please review the attached log file."; objMailMessage.From = ConfigurationSettings.AppSettings["EmailFrom"]; objMailMessage.To = ConfigurationSettings.AppSettings["EmailTo"]; objMailMessage.Subject = "-- Log Message --"; if (File.Exists(this.LogFile)) { MailAttachment objAttachment = new MailAttachment(this.LogFile); objMailMessage.Attachments.Add(objAttachment); } SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SMTPServer"]; SmtpMail.Send( objMailMessage ); }
private bool WsSendSimpleEmail(string subject, string message, string emailAddress, List<string> attachmentPaths, Guid currentUserId) { try { System.Web.Mail.MailFormat format = new System.Web.Mail.MailFormat(); string FromEmail = "*****@*****.**"; string Password = "******"; System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage(); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com"); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465"); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2"); //sendusing: cdoSendUsingPort, value 2, for sending the message using //the network. //smtpauthenticate: Specifies the mechanism used when authenticating //to an SMTP //service over the network. Possible values are: //- cdoAnonymous, value 0. Do not authenticate. //- cdoBasic, value 1. Use basic clear-text authentication. //When using this option you have to provide the user name and password //through the sendusername and sendpassword fields. //- cdoNTLM, value 2. The current process security context is used to // authenticate with the service. myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //Use 0 for anonymous myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", FromEmail); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMail.From = FromEmail; myMail.Subject = subject; myMail.BodyFormat = format; myMail.Body = message; foreach (string path in attachmentPaths) { if (path.Trim() != "") { MailAttachment MyAttachment = new MailAttachment(path); myMail.Attachments.Add(MyAttachment); } } System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:465"; myMail.To = emailAddress; System.Web.Mail.SmtpMail.Send(myMail); } catch (Exception ex) { throw; } return true; }
/// <summary> /// Sends an e-mail via SMTP. /// </summary> /// <param name="entity">Email entity to send</param> public void Send(Email entity) { MailMessage mailMessage = new MailMessage(); mailMessage.From = Configuration.MailFrom; //entity.To = "[email protected];[email protected];"; //mailMessage.Bcc = entity.To; if (entity.Cc.Length > 0) { mailMessage.Cc = entity.Cc; } mailMessage.Subject = entity.Subject; mailMessage.Body = entity.MailBody; mailMessage.BodyFormat = MailFormat.Text; mailMessage.BodyEncoding = Encoding.UTF8; entity.EmailAttachments = base.SelectChildrenByAttachmentOfEmail(entity.ID); // // A csatolt file-ok küldéséhez egy könyvtat hozunk létre és majd ide másoljuk a // levélhez csatolandó file-okat // string sendEmailTempDirPath = "EmailAttachments"; string fileDir = Path.Combine(Configuration.FileStoreFolder, "Emails\\" + entity.ID.Value.ToString()); DirectoryInfo di = new DirectoryInfo(fileDir); di.CreateSubdirectory(sendEmailTempDirPath); foreach (EmailAttachment attachment in entity.EmailAttachments.All) { string fileFullPath = Path.Combine(fileDir, attachment.ID.Value.ToString()); // // Átmásoljuk és átnevezzük a file-okat // EmailAttachmentService s = new EmailAttachmentService(); EmailAttachment ea = s.EmailAttachmentSelect(attachment.ID); string sendFileFullPath = Path.Combine(fileDir, Path.Combine(sendEmailTempDirPath, ea.Path)); string fileExtension = ea.Path.Substring(ea.Path.LastIndexOf(".")); // File-ok másolása ... File.Copy(fileFullPath + fileExtension, sendFileFullPath, true); MailAttachment mailAttachment = new MailAttachment(sendFileFullPath); mailMessage.Attachments.Add(mailAttachment); } // TODO: ReplyTo mezot így lehet kitölteni // Ezt a konfigba is ki kell vezetni //mailMessage.Headers.Add( "Reply-To", "*****@*****.**"); // elmentjük az entitást ... sikertelen küldé esetére base.EmailUpdate(entity); #if (!DEBUG) // // A spamszűrés elkerülése érdekében egyessével küldjük ki az e-mail-eket // SmtpMail.SmtpServer = Configuration.SmtpServer; string origSendTo = entity.To; string[] sendTo = origSendTo.Split(';'); for (int i = 0; i < sendTo.Length; i++) { if (sendTo[i] != "") { mailMessage.To = sendTo[i]; SmtpMail.Send(mailMessage); } } #endif }
/// <summary> /// This is where the work is done. /// </summary> protected override void ExecuteTask() { MailMessage mailMessage = new MailMessage(); mailMessage.From = this.From; mailMessage.To = this.ToList; mailMessage.Bcc = this.BccList; mailMessage.Cc = this.CcList; mailMessage.Subject = this.Subject; mailMessage.BodyFormat = this.Format; // ensure base directory is set, even if fileset was not initialized // from XML if (Files.BaseDirectory == null) { Files.BaseDirectory = new DirectoryInfo(Project.BaseDirectory); } if (Attachments.BaseDirectory == null) { Attachments.BaseDirectory = new DirectoryInfo(Project.BaseDirectory); } // begin build message body StringWriter bodyWriter = new StringWriter(CultureInfo.InvariantCulture); if (!StringUtils.IsNullOrEmpty(Message)) { bodyWriter.WriteLine(Message); bodyWriter.WriteLine(); } // append file(s) to message body foreach (string fileName in Files.FileNames) { try { string content = ReadFile(fileName); if (!StringUtils.IsNullOrEmpty(content)) { bodyWriter.Write(content); bodyWriter.WriteLine(string.Empty); } } catch (Exception ex) { Log(Level.Warning, string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1135"), fileName, ex.Message)); } } // add message body to mailMessage string bodyText = bodyWriter.ToString(); if (bodyText.Length != 0) { mailMessage.Body = bodyText; } // add attachments to message foreach (string fileName in Attachments.FileNames) { try { MailAttachment attachment = new MailAttachment(fileName); mailMessage.Attachments.Add(attachment); } catch (Exception ex) { Log(Level.Warning, string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1136"), fileName, ex.Message)); } } // send message try { Log(Level.Info, "Sending mail to {0}.", mailMessage.To); SmtpMail.SmtpServer = this.Mailhost; SmtpMail.Send(mailMessage); } catch (Exception ex) { StringBuilder msg = new StringBuilder(); msg.Append("Error enountered while sending mail message." + Environment.NewLine); msg.Append("Make sure that mailhost=" + this.Mailhost + " is valid" + Environment.NewLine); throw new BuildException("Error sending mail:" + Environment.NewLine + msg.ToString(), Location, ex); } }
internal static void Send(MailMessage message) { object obj2 = _helper.CreateInstance(); if (message.From != null) { _helper.SetProp(obj2, "From", message.From); } if (message.To != null) { _helper.SetProp(obj2, "To", message.To); } if (message.Cc != null) { _helper.SetProp(obj2, "Cc", message.Cc); } if (message.Bcc != null) { _helper.SetProp(obj2, "Bcc", message.Bcc); } if (message.Subject != null) { _helper.SetProp(obj2, "Subject", message.Subject); } if (message.Priority != MailPriority.Normal) { int propValue = 0; switch (message.Priority) { case MailPriority.Normal: propValue = 1; break; case MailPriority.Low: propValue = 0; break; case MailPriority.High: propValue = 2; break; } _helper.SetProp(obj2, "Importance", propValue); } if (message.BodyEncoding != null) { _helper.CallMethod(obj2, "SetLocaleIDs", new object[] { message.BodyEncoding.CodePage }); } if (message.UrlContentBase != null) { _helper.SetProp(obj2, "ContentBase", message.UrlContentBase); } if (message.UrlContentLocation != null) { _helper.SetProp(obj2, "ContentLocation", message.UrlContentLocation); } if (message.Headers.Count > 0) { IDictionaryEnumerator enumerator = message.Headers.GetEnumerator(); while (enumerator.MoveNext()) { string key = (string)enumerator.Key; string str2 = (string)enumerator.Value; _helper.SetProp(obj2, "Value", key, str2); } } if (message.BodyFormat == MailFormat.Html) { _helper.SetProp(obj2, "BodyFormat", 0); _helper.SetProp(obj2, "MailFormat", 0); } _helper.SetProp(obj2, "Body", (message.Body != null) ? message.Body : string.Empty); IEnumerator enumerator2 = message.Attachments.GetEnumerator(); while (enumerator2.MoveNext()) { MailAttachment current = (MailAttachment)enumerator2.Current; int num3 = 0; switch (current.Encoding) { case MailEncoding.UUEncode: num3 = 0; break; case MailEncoding.Base64: num3 = 1; break; } object[] args = new object[3]; args[0] = current.Filename; args[2] = num3; _helper.CallMethod(obj2, "AttachFile", args); } _helper.CallMethod(obj2, "Send", new object[5]); Marshal.ReleaseComObject(obj2); }
/// <summary> /// 邮件发送方法(带附件) /// </summary> /// <param name="pMailto">收件人地址。如:[email protected]</param> /// <param name="pMailsubject">邮件标题</param> /// <param name="pMailbody">邮件正文</param> /// <param name="pAttachments">附件的文件路径</param> /// <returns></returns> public static bool SendMail(string pMailto, string pMailsubject, string pMailbody, string[] pAttachments) { try { string smtpServer = "smtp.exmail.qq.com"; string sendFrom = "*****@*****.**"; string username = "******"; string password = "******"; #region 新邮件的发送信息 smtpServer = "smtp.exmail.qq.com"; sendFrom = "*****@*****.**"; username = "******"; password = "******"; #endregion if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["SmtpServer"])) { smtpServer = ConfigurationManager.AppSettings["SmtpServer"]; } if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["MailSendFrom"])) { sendFrom = ConfigurationManager.AppSettings["MailSendFrom"]; } if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["MailUserName"])) { username = ConfigurationManager.AppSettings["MailUserName"]; } if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["MailUserPassword"])) { password = ConfigurationManager.AppSettings["MailUserPassword"]; } MailMessage mailObj = new MailMessage(); mailObj.BodyEncoding = System.Text.UTF8Encoding.UTF8; SmtpMail.SmtpServer = smtpServer; mailObj.From = sendFrom; mailObj.To = pMailto; mailObj.Priority = MailPriority.High; mailObj.BodyFormat = MailFormat.Html; mailObj.Subject = pMailsubject; mailObj.Body = pMailbody; mailObj.Fields.Add(@"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); mailObj.Fields.Add(@"http://schemas.microsoft.com/cdo/configuration/sendusername", username); mailObj.Fields.Add(@"http://schemas.microsoft.com/cdo/configuration/sendpassword", password); //添加附件 if (pAttachments != null) { foreach (string pAttachment in pAttachments) { if (System.IO.File.Exists(pAttachment)) { var attachment = new System.Web.Mail.MailAttachment(pAttachment); mailObj.Attachments.Add(attachment); } else { Log.Loggers.Debug(new Log.DebugLogInfo() { Message = "指定的附件不存在:【" + pAttachment + "】" }); } } } SmtpMail.Send(mailObj); return(true); } catch (Exception ex) { //Log.Loggers.Exception(new Log.ExceptionLogInfo(ex)); return(false); } }
public static byte SendMail (string sender, string title, string server, string file) { byte response; MailMessage msg = new MailMessage (); MailAttachment nitem = new MailAttachment (file); msg.From = sender; msg.Subject = "MWN Contribution: " + title; msg.To = "*****@*****.**"; msg.Attachments.Add (nitem); if (server != null) SmtpMail.SmtpServer = server; Console.WriteLine ("Sending..."); try { SmtpMail.Send (msg); response = 0; } catch (Exception e) { Console.WriteLine (e); response = 1; } return response; }
// sends a multipart mail to the server void SendMultipartMail(MailMessageWrapper msg) { // generate the boundary between attachments string boundary = MailUtil.GenerateBoundary(); // set the Content-Type header to multipart/mixed string bodyContentType = msg.Header.ContentType; msg.Header.ContentType = String.Concat("multipart/mixed;\r\n boundary=", boundary); // write the header smtp.WriteHeader(msg.Header); // write the first part text part // before the attachments smtp.WriteBoundary(boundary); MailHeader partHeader = new MailHeader(); partHeader.ContentType = bodyContentType; #if NET_1_1 // Add all the custom headers to body part as specified in //Fields property of MailMessageWrapper //Remove fields specific for authenticating to SMTP server. //Need to incorporate AUTH command in SmtpStream to handle //Authorization info. Its a temporary fix for Bug no 68829. //Will dig some more on SMTP AUTH command, and then implement //Authorization. - Sanjay if (msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] != null) { msg.Fields.Data.Remove("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"); } if (msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/sendusername"] != null) { msg.Fields.Data.Remove("http://schemas.microsoft.com/cdo/configuration/sendusername"); } if (msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/sendpassword"] != null) { msg.Fields.Data.Remove("http://schemas.microsoft.com/cdo/configuration/sendpassword"); } partHeader.Data.Add(msg.Fields.Data); #endif smtp.WriteHeader(partHeader); // FIXME: probably need to use QP or Base64 on everything higher // then 8-bit .. like utf-16 smtp.WriteBytes(msg.BodyEncoding.GetBytes(msg.Body)); smtp.WriteBoundary(boundary); // now start to write the attachments for (int i = 0; i < msg.Attachments.Count; i++) { MailAttachment a = (MailAttachment)msg.Attachments[i]; FileInfo fileInfo = new FileInfo(a.Filename); MailHeader aHeader = new MailHeader(); aHeader.ContentType = String.Concat(MimeTypes.GetMimeType(fileInfo.Name), "; name=\"", fileInfo.Name, "\""); aHeader.ContentDisposition = String.Concat("attachment; filename=\"", fileInfo.Name, "\""); aHeader.ContentTransferEncoding = a.Encoding.ToString(); smtp.WriteHeader(aHeader); // perform the actual writing of the file. // read from the file stream and write to the tcp stream FileStream ins = fileInfo.OpenRead(); // create an apropriate encoder IAttachmentEncoder encoder; if (a.Encoding == MailEncoding.UUEncode) { encoder = new UUAttachmentEncoder(644, fileInfo.Name); } else { encoder = new Base64AttachmentEncoder(); } encoder.EncodeStream(ins, smtp.Stream); ins.Close(); smtp.WriteLine(""); // if it is the last attachment write // the final boundary otherwise write // a normal one. if (i < (msg.Attachments.Count - 1)) { smtp.WriteBoundary(boundary); } else { smtp.WriteFinalBoundary(boundary); } } }
void btnSubmit_Click(Object sender, EventArgs e) { string sTo, sFrom, sSubject, sBody; string sAttach, sCc, sBcc, sBodyEncoding; string sBodyFormat, sMailServer, sPriority; string sUrlContentBase, sUrlContentLocation; int iLoop1; sTo = txtTo.Text.Trim(); sFrom = txtFrom.Text.Trim(); sSubject = txtSubject.Text.Trim(); sBody = txtBody.Text.Trim(); sAttach = txtAttach.Text.Trim(); sCc = txtCc.Text.Trim(); sBcc = txtBcc.Text.Trim(); sBodyFormat = txtBodyFormat.Text.Trim(); sBodyEncoding = txtBodyEncoding.Text.Trim(); sPriority = txtPriority.Text.Trim(); sUrlContentBase = txtUrlContentBase.Text.Trim(); sUrlContentLocation = txtUrlContentLocation.Text.Trim(); sMailServer = txtMailServer.Text.Trim(); MailMessage MyMail = new MailMessage(); MyMail.From = sFrom; MyMail.To = sTo; MyMail.Subject = sSubject; MyMail.Body = sBody; MyMail.Cc = sCc; MyMail.Bcc = sBcc; MyMail.UrlContentBase = sUrlContentBase; MyMail.UrlContentLocation = sUrlContentLocation; if (txtBodyEncoding.Text == Encoding.UTF7.EncodingName) MyMail.BodyEncoding = Encoding.UTF7; else if (txtBodyEncoding.Text == Encoding.UTF8.EncodingName) MyMail.BodyEncoding = Encoding.UTF8; else MyMail.BodyEncoding = Encoding.ASCII; switch (sBodyFormat.ToUpper()) { case "HTML": MyMail.BodyFormat = MailFormat.Html; break; default: MyMail.BodyFormat = MailFormat.Text; break; } switch (sPriority.ToUpper()) { case "HIGH": MyMail.Priority = MailPriority.High; break; case "LOW": MyMail.Priority = MailPriority.Low; break; default: MyMail.Priority = MailPriority.Normal; break; } // Build an IList of mail attachments. if (sAttach != "") { char[] delim = new char[] { ',' }; foreach (string sSubstr in sAttach.Split(delim)) { MailAttachment MyAttachment = new MailAttachment(sSubstr); MyMail.Attachments.Add(MyAttachment); } } SmtpMail.SmtpServer = sMailServer; SmtpMail.Send(MyMail); lblMsg1.Text = "C# Message sent to " + MyMail.To; }
internal static void Send(MailMessage message) { // create mail object Object newMail = _helper.CreateInstance(); // set properties if (message.From != null) { _helper.SetProp(newMail, "From", message.From); } if (message.To != null) { _helper.SetProp(newMail, "To", message.To); } if (message.Cc != null) { _helper.SetProp(newMail, "Cc", message.Cc); } if (message.Bcc != null) { _helper.SetProp(newMail, "Bcc", message.Bcc); } if (message.Subject != null) { _helper.SetProp(newMail, "Subject", message.Subject); } if (message.Priority != MailPriority.Normal) { int p = 0; switch (message.Priority) { case MailPriority.Low: p = 0; break; case MailPriority.Normal: p = 1; break; case MailPriority.High: p = 2; break; } _helper.SetProp(newMail, "Importance", p); } if (message.BodyEncoding != null) { _helper.CallMethod(newMail, "SetLocaleIDs", new Object[1] { message.BodyEncoding.CodePage }); } if (message.UrlContentBase != null) { _helper.SetProp(newMail, "ContentBase", message.UrlContentBase); } if (message.UrlContentLocation != null) { _helper.SetProp(newMail, "ContentLocation", message.UrlContentLocation); } int numHeaders = message.Headers.Count; if (numHeaders > 0) { IDictionaryEnumerator e = message.Headers.GetEnumerator(); while (e.MoveNext()) { String k = (String)e.Key; String v = (String)e.Value; _helper.SetProp(newMail, "Value", k, v); } } if (message.BodyFormat == MailFormat.Html) { _helper.SetProp(newMail, "BodyFormat", 0); _helper.SetProp(newMail, "MailFormat", 0); } if (message.Body != null) { _helper.SetProp(newMail, "Body", message.Body); } for (IEnumerator e = message.Attachments.GetEnumerator(); e.MoveNext();) { MailAttachment a = (MailAttachment)e.Current; int c = 0; switch (a.Encoding) { case MailEncoding.UUEncode: c = 0; break; case MailEncoding.Base64: c = 1; break; } _helper.CallMethod(newMail, "AttachFile", new Object[3] { a.Filename, null, (Object)c }); } // send mail _helper.CallMethod(newMail, "Send", new Object[5] { null, null, null, null, null }); // close unmanaged COM classic component Marshal.ReleaseComObject(newMail); }
internal static void Send(MailMessage message) { // create message object Object m = _helper.CreateInstance(); // set properties if (message.From != null) { _helper.SetProp(m, "From", message.From); } if (message.To != null) { _helper.SetProp(m, "To", message.To); } if (message.Cc != null) { _helper.SetProp(m, "Cc", message.Cc); } if (message.Bcc != null) { _helper.SetProp(m, "Bcc", message.Bcc); } if (message.Subject != null) { _helper.SetProp(m, "Subject", message.Subject); } if (message.Priority != MailPriority.Normal) { String importance = null; switch (message.Priority) { case MailPriority.Low: importance = "low"; break; case MailPriority.Normal: importance = "normal"; break; case MailPriority.High: importance = "high"; break; } if (importance != null) { SetField(m, "importance", importance); } } if (message.BodyEncoding != null) { Object body = _helper.GetProp(m, "BodyPart"); LateBoundAccessHelper.SetPropStatic(body, "Charset", message.BodyEncoding.BodyName); Marshal.ReleaseComObject(body); } if (message.UrlContentBase != null) { SetField(m, "content-base", message.UrlContentBase); } if (message.UrlContentLocation != null) { SetField(m, "content-location", message.UrlContentLocation); } int numHeaders = message.Headers.Count; if (numHeaders > 0) { IDictionaryEnumerator e = message.Headers.GetEnumerator(); while (e.MoveNext()) { SetField(m, (String)e.Key, (String)e.Value); } } if (message.Body != null) { if (message.BodyFormat == MailFormat.Html) { _helper.SetProp(m, "HtmlBody", message.Body); } else { _helper.SetProp(m, "TextBody", message.Body); } } for (IEnumerator e = message.Attachments.GetEnumerator(); e.MoveNext();) { MailAttachment a = (MailAttachment)e.Current; Object bodyPart = _helper.CallMethod(m, "AddAttachment", new Object[3] { a.Filename, null, null }); if (a.Encoding == MailEncoding.UUEncode) { _helper.SetProp(m, "MimeFormatted", false); } if (bodyPart != null) { Marshal.ReleaseComObject(bodyPart); } } // optional SMTP server String server = SmtpMail.SmtpServer; if (server.Length == 0) { server = null; } if (server != null || message.Fields.Count > 0) { Object config = LateBoundAccessHelper.GetPropStatic(m, "Configuration"); if (config != null) { if (server != null) { LateBoundAccessHelper.SetPropStatic(config, "Fields", "http://schemas.microsoft.com/cdo/configuration/sendusing", (Object)2); LateBoundAccessHelper.SetPropStatic(config, "Fields", "http://schemas.microsoft.com/cdo/configuration/smtpserver", server); LateBoundAccessHelper.SetPropStatic(config, "Fields", "http://schemas.microsoft.com/cdo/configuration/smtpserverport", (Object)25); } foreach (DictionaryEntry e in message.Fields) { LateBoundAccessHelper.SetPropStatic(config, "Fields", (String)e.Key, e.Value); } Object fields = LateBoundAccessHelper.GetPropStatic(config, "Fields"); LateBoundAccessHelper.CallMethodStatic(fields, "Update", new Object[0]); Marshal.ReleaseComObject(fields); Marshal.ReleaseComObject(config); } } // send mail _helper.CallMethod(m, "Send", new Object[0]); // close unmanaged COM classic component Marshal.ReleaseComObject(m); }
/// <summary> /// 邮件发送方法(带附件) /// </summary> /// <param name="pFrom">发送方</param> /// <param name="pMailTo">收件人地址。如:[email protected]</param> /// <param name="pMailSubject">邮件标题</param> /// <param name="pMailBody">邮件正文</param> /// <param name="pAttachments">附件的文件路径</param> /// <returns></returns> public static bool SendMail(FromSetting pFrom, string pMailTo, string pMailSubject, string pMailBody, string[] pAttachments) { //参数检查 if (pFrom == null) { throw new ArgumentNullException("pFrom"); } if (string.IsNullOrWhiteSpace(pFrom.Password)) { throw new ArgumentNullException("pFrom.Password"); } if (string.IsNullOrWhiteSpace(pFrom.SendFrom)) { throw new ArgumentNullException("pFrom.SendFrom"); } if (string.IsNullOrWhiteSpace(pFrom.SMTPServer)) { throw new ArgumentNullException("pFrom.SMTPServer"); } if (string.IsNullOrWhiteSpace(pFrom.UserName)) { throw new ArgumentNullException("pFrom.UserName"); } // try { MailMessage mailObj = new MailMessage(); mailObj.BodyEncoding = System.Text.UTF8Encoding.UTF8; SmtpMail.SmtpServer = pFrom.SMTPServer; mailObj.From = pFrom.SendFrom; mailObj.To = pMailTo; mailObj.Priority = MailPriority.High; mailObj.BodyFormat = MailFormat.Html; mailObj.Subject = pMailSubject; mailObj.Body = pMailBody; mailObj.Fields.Add(@"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); mailObj.Fields.Add(@"http://schemas.microsoft.com/cdo/configuration/sendusername", pFrom.UserName); mailObj.Fields.Add(@"http://schemas.microsoft.com/cdo/configuration/sendpassword", pFrom.Password); //添加附件 if (pAttachments != null) { foreach (string pAttachment in pAttachments) { if (System.IO.File.Exists(pAttachment)) { var attachment = new System.Web.Mail.MailAttachment(pAttachment); mailObj.Attachments.Add(attachment); } else { Log.Loggers.Debug(new Log.DebugLogInfo() { Message = "指定的附件不存在:【" + pAttachment + "】" }); } } } SmtpMail.Send(mailObj); return(true); } catch { return(false); } }
public void SendMailWithAttachment(string toName, string toEmail, string subject, string mailBody,string attachment) { try { bool fSSL = true; //string sHost = "smtp.zoho.com"; string sHost = "smtp.gmail.com";// "smtpout.asia.secureserver.net"; // mSmtpClient.Port = 80; int nPort = 465; string sUserName = "******"; string sPassword = "******"; string sFromName = "i4i Application"; string sFromEmail = "*****@*****.**"; string sToName = toName;// "*****@*****.**"; string sToEmail = toEmail;// "*****@*****.**"; string sHeader = subject; string sMessage = ""; sMessage += "<table width='100%' cellpadding='0' cellspacing='0' align='center' bgcolor='#eaedf2' style='background-color: #;'> "; sMessage += "<tr><td width='100%' height='20'></td> </tr>"; sMessage += "<tr><td valign='top'><table class='BoxWrap' width='600' align='center' cellpadding='0' cellspacing='0' >"; sMessage += "<tr><td class='RespoLogoW'><a href='http://www.i4i.co.in/' style='border: none;'> "; sMessage += "<img class='RespoLogo' width='200' src='http://www.i4i.co.in/wp-content/uploads/2014/06/logo.png' alt='' border='0' style='width: 50px; display: block; border: 0px; outline: none; text-decoration: none;' /> "; sMessage += "</a></td><td valign='bottom'><h3 style='text-align: right; font-size: 12px; color: #a4a4a4; font-weight: normal;font-family: Helvetica, Arial, sans-serif;'>"; sMessage += "</h3></td></tr></table></td></tr>"; sMessage += "<tr><td width='100%' height='20'></td></tr><tr><td valign='top'><table class='BoxWrap' width='600' align='center' cellpadding='0' cellspacing='0' style='background-color: #ffffff;margin-bottom:40px;'>"; sMessage += "<tr><td><table width='100%' cellspacing='0'><tr><td style='background-color: #eb5d37;' height='5'></td></tr></table> </td></tr> "; sMessage += "<tr><td><table width='100%' cellpadding='30' cellspacing='0'><tr><td style='border-bottom: 1px solid #e0e0e0;'>"; sMessage += "<h1 style='margin: 0 0 20px 0; font-family: Georgia, Helvetica, Arial, sans-serif;font-size: 17px !important; font-weight: bold; font-style: italic; color: #27a9e3; text-align: left;line-height: 18px;'>"; sMessage += "Hi " + sToName + ",<br/></h1>"; sMessage += mailBody + "<br/><br/>" + "http://www.i4i.co.in/" + "<br/><br/>"; sMessage += "<h2 style='margin: 0 0 20px 0; font-size: 14px; color: #eb5d37; text-align: left;font-weight: bold; font-family: Helvetica, Arial, sans-serif; line-height: 22px;'>"; sMessage += "Sincerely,<br />i4i Engineering</h2></td></tr></table></td></tr></table></td></tr></table> "; if (sToName.Length == 0) sToName = sToEmail; if (sFromName.Length == 0) sFromName = sFromEmail; System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage(); Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = sHost; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = nPort.ToString(); if (fSSL) Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true"; if (sUserName.Length == 0) { //Ingen auth } else { Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sUserName; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sPassword; } Mail.To = sToEmail; Mail.From = sFromEmail; Mail.Subject = sHeader; Mail.Body = sMessage; Mail.BodyFormat = System.Web.Mail.MailFormat.Html; MailAttachment attachFile = new MailAttachment (attachment); Mail.Attachments.Add(attachFile); System.Web.Mail.SmtpMail.SmtpServer = sHost; System.Web.Mail.SmtpMail.Send(Mail); Mail = null; //updateMailUserStatus(dr);//Updating MailSendServiceData Table to update sentStatus=true and Inserting reward Details } catch (Exception ex) { //throw new Exception(ex.Message); } }
public void CreateAndSendEmails(int orderID, string pdfFilePath) { BPOrders bpOrder = new BPOrders(); BPOrderDetails bpDetails = new BPOrderDetails(); BEOrders dsOrder = bpOrder.SelectOrdersByID(orderID); dsOrder.Merge(bpDetails.SelectOrderDetailsWithInventoryByOrderID(orderID)); BEOrders.tbl_OrdersRow order = (BEOrders.tbl_OrdersRow) dsOrder.tbl_Orders.Rows[0]; BPCompanyEmails bp = new BPCompanyEmails(); BPCompanies bpCompany = new BPCompanies(); BPCompanyAliases bpAliases = new BPCompanyAliases(); BECompanies ds = bp.SelectActiveCompanyEmailsByCompanyID(order.CompanyID); ds.Merge(bpCompany.SelectCompaniesByID(order.CompanyID)); ds.Merge(bpAliases.SelectCompanyColumnsByCompanyID(order.CompanyID)); BECompanies.tbl_CompanyAliasesRow aliases = (BECompanies.tbl_CompanyAliasesRow) ds.tbl_CompanyAliases.Rows[0]; BECompanies.tbl_CompaniesRow company; bool hasHuntingInventoryAccess = false; string CompanyImage = ""; if(ds.tbl_Companies.Count > 0) { company = (BECompanies.tbl_CompaniesRow) ds.tbl_Companies.Rows[0]; if (!company.IsCompanyImageIDNull()) { BPImages bpImages = new BPImages(); BEImages DSImages = bpImages.SelectByID(company.CompanyImageID); string imageName = DSImages.tbl_Images.FindByImageID(company.CompanyImageID).ImageName; CompanyImage = "<img src='" + companyLogoPath + "l_" + imageName + "' />"; } hasHuntingInventoryAccess = company.CompanyRentalInventory; } MailMessage mm = new MailMessage(); mm.Subject = "Confirmation of " + _EmailType.ToUpper() + " ID:" + orderID; foreach (BECompanies.tbl_CompanyEmailsRow row in ds.tbl_CompanyEmails.Rows) { mm.To += row.CompanyEmail + ";"; } mm.From = ConfigurationSettings.AppSettings.Get("AdministratorEmailFrom"); mm.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = Convert.ToInt32(ConfigurationSettings.AppSettings["SmtpServerPort"]); SmtpMail.SmtpServer = ConfigurationSettings.AppSettings.Get("SmtpServer"); string createOrder = ""; createOrder += "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>"; createOrder += "<Html><head><LINK href='" + cssLinkPath + "screen.css' type='text/css' rel='stylesheet'></head><body class='alignleft'><div class='top'></div><div class='wrap'>"; createOrder += "<table border='0' cellspacing='0' cellpadding='0' style='margin-bottom:10px;' class='tablewidth'><tr>"; createOrder += "<td><img src='" + huntingLogoPath + "' /></td>"; createOrder += "<td style='text-align:right;'>" + CompanyImage + "</td>"; createOrder += "</tr></table>"; //new order details table createOrder += "<table class='orderdetails tablewidth'>"; createOrder += "<tr><th colspan='4' class='heading'>Confirmation of " + _EmailType.ToUpper() + " ID: " + order.OrderID + "</th></tr><tr>"; createOrder += "<th width='20%'>Date</th>"; createOrder += "<td width='30%'>" + order.OrderDate.ToString("MMM d, yyyy h:mm tt") + "</td>"; createOrder += "<th width='20%'> </th>"; createOrder += "<td width='30%'> </td>"; createOrder += "</tr>"; createOrder += "<tr>"; if (_EmailType == "Order") { createOrder += "<th>Ordered By </th>"; } else { createOrder += "<th>Received By </th>"; } createOrder += "<td>" + order.OrderRequestedBy + "</td>"; createOrder += "<th width='16%'>Rig </th>"; createOrder += "<td width='34%'>" + order.OrderRigNumber + "</td>"; createOrder += "</tr>"; createOrder += "<tr>"; createOrder += "<th>Ship To </th>"; createOrder += "<td>" + order.OrderShipTo + "</td>"; createOrder += "<th>Job # </th>"; createOrder += "<td>" + order.OrderJobNumber + "</td>"; createOrder += "</tr>"; createOrder += "<tr>"; createOrder += "<th>Via </th>"; createOrder += "<td>" + order.OrderShipVIA + "</td>"; createOrder += "<th>Lease </th>"; createOrder += "<td>" + order.OrderLeaseNumber + "</td>"; createOrder += "</tr>"; createOrder += "<tr>"; if (_EmailType == "Order") { createOrder += "<th>Date Required </th>"; } else { createOrder += "<th>Date Received </th>"; } createOrder += "<td>" + order.OrderDateRequired.ToString("MMM d, yyyy") + "</td>"; if (_EmailType == "Order") { createOrder += "<th>Time Required</th>"; } else { createOrder += "<th>Time Received</th>"; } createOrder += "<td>" + order.OrderTimeRequired + "</td>"; createOrder += "</tr>"; createOrder += "<tr>"; createOrder += "<th>Comments</th>"; createOrder += "<td colspan='3'>" + order.OrderComments + "</td>"; createOrder += "</tr></table><div style='page-break-after:avoid'> </div>"; ArrayList columns = new ArrayList(); createOrder += "<table class='emailitemdetails'><tr>"; if(hasHuntingInventoryAccess) { createOrder += "<th width='40px'>B/R</th>"; columns.Add("BuyRentStatus"); } createOrder += "<th>" + aliases.ItemNumber + "</th>"; columns.Add("ItemNumber"); createOrder += "<th>" + aliases.Description + "</th>"; columns.Add("Description"); createOrder += "<th>" + aliases.Box + "</th>"; columns.Add("Box"); createOrder += "<th>" + aliases.Pin + "</th>"; columns.Add("Pin"); createOrder += "<th>" + aliases.MajorOD + "</th>"; columns.Add("MajorOD"); createOrder += "<th>" + aliases.MinorOD + "</th>"; columns.Add("MinorOD"); createOrder += "<th>" + aliases.InsideDiameter + "</th>"; columns.Add("InsideDiameter"); createOrder += "<th>" + aliases.SealtoSealLength + "</th>"; columns.Add("SealtoSealLength"); createOrder += "<th>" + aliases.FloatBore + "</th>"; columns.Add("FloatBore"); createOrder += "<th>" + aliases.Box2 + "</th>"; columns.Add("Box2"); createOrder += "<th>" + aliases.GeneralComments + "</th>"; columns.Add("GeneralComments"); if (!aliases.IsExtraColumn1Null()) { createOrder += "<th>" + aliases.ExtraColumn1 + "</th>"; columns.Add("ExtraColumn1"); } if (!aliases.IsExtraColumn2Null()) { createOrder += "<th>" + aliases.ExtraColumn2 + "</th>"; columns.Add("ExtraColumn2"); } if (!aliases.IsExtraColumn3Null()) { createOrder += "<th>" + aliases.ExtraColumn3 + "</th>"; columns.Add("ExtraColumn3"); } if (!aliases.IsExtraColumn4Null()) { createOrder += "<th>" + aliases.ExtraColumn4 + "</th>"; columns.Add("ExtraColumn4"); } if (!aliases.IsExtraColumn5Null()) { createOrder += "<th>" + aliases.ExtraColumn5 + "</th>"; columns.Add("ExtraColumn5"); } if (!aliases.IsExtraColumn6Null()) { createOrder += "<th>" + aliases.ExtraColumn6 + "</th>"; columns.Add("ExtraColumn6"); } if (!aliases.IsExtraColumn7Null()) { createOrder += "<th>" + aliases.ExtraColumn7 + "</th>"; columns.Add("ExtraColumn7"); } if (!aliases.IsExtraColumn8Null()) { createOrder += "<th>" + aliases.ExtraColumn8 + "</th>"; columns.Add("ExtraColumn8"); } if (!aliases.IsExtraColumn9Null()) { createOrder += "<th>" + aliases.ExtraColumn9 + "</th>"; columns.Add("ExtraColumn9"); } if (!aliases.IsExtraColumn10Null()) { createOrder += "<th>" + aliases.ExtraColumn10 + "</th>"; columns.Add("ExtraColumn10"); } createOrder += "<td class='lastcell'> </td></tr>"; int rowCount = 0; string strColor2 = ""; foreach (BEOrders.tbl_OrderDetailsRow item in dsOrder.tbl_OrderDetails.Rows) { rowCount += 1; if (rowCount % 2 == 0) { strColor2 = "#efefef"; } else { strColor2 = "#ffffff"; } createOrder += "<tr style='page-break-inside:avoid'>"; foreach (string col in columns) { if (item[col] != null && item[col].ToString() != "") { if(col == "BuyRentStatus") createOrder += "<td nowrap bgColor='" + strColor2 + "'>" + item[col].ToString() + "</td>"; else createOrder += "<td bgColor='" + strColor2 + "'>" + item[col].ToString() + "</td>"; } else { createOrder += "<td bgColor='" + strColor2 + "'> </td>"; } } createOrder += "<td class='lastcell'> </td></tr>"; } createOrder += "</table>"; createOrder += "<br><div style='page-break-inside:avoid;'><hr><table cellpadding='0' cellspacing='0' border='0' align='center'>"; createOrder += "<tr><td align='center'>"; createOrder += "If you require further clarification please call Mazz Oilfield Services. Customer Service at (403) 720-6299."; createOrder += "<br/>"; createOrder += " Thank you for using Mazz Oilfield Services Online!"; createOrder += "</td></tr></table><hr></div>"; createOrder += "<br><table class='shippingdept' style='width: 550px !important;' align='center'>"; createOrder += "<tr><th colspan='2' class='heading'>ORDER ID: " + order.OrderID + " - Shipping Verification</th></tr>"; createOrder += "<tr><th>Information Check List</th><th width='50%'>Shipper's Initial</td></th>"; createOrder += "<tr bgColor='#efefef'><td><img src='" + activeIconPath + "'> Check Box Connections</td><td> </td></tr>"; createOrder += "<tr><td><img src='" + activeIconPath + "'> Check Pin Connections</td><td> </td></tr>"; createOrder += "<tr bgColor='#efefef'><td><img src='" + activeIconPath + "'> Check Serial Numbers</td><td> </td></tr>"; createOrder += "<tr><td><img src='" + activeIconPath + "'> Gauge Float Bore</td><td> </td></tr>"; createOrder += "<tr bgColor='#efefef'><td><img src='" + activeIconPath + "'> Gauge UBHO Bore</td><td> </td></tr>"; createOrder += "<tr><td><img src='" + activeIconPath + "'> Check Protectors</td><td> </td></tr>"; createOrder += "</table><br>"; createOrder += "<br><table class='receiver' align='center'>"; createOrder += "<tr><td align='left'>All Items Verified and Thread Protectors Installed:</td><td align='center'>____________________________________</td></tr>"; createOrder += "<tr><td> </td><td align='center'>RECEIVER</td></tr>"; createOrder += "</table></br>"; createOrder += "</div><div class='bottom'></div>"; createOrder += "</body></html>"; string pdfFileName = "ConfirmOrderID_" + orderID + ".pdf"; string fullPDFFilePath = pdfFilePath + pdfFileName; ConvertHTMLToPDF(createOrder, fullPDFFilePath); try { mm.Body = "Please review the attached PDF file for Order Confirmation"; MailAttachment pdfAttachment = new MailAttachment(fullPDFFilePath); mm.Attachments.Add(pdfAttachment); mm.BodyFormat = MailFormat.Html; SmtpMail.Send(mm); if (File.Exists(fullPDFFilePath)) File.Delete(fullPDFFilePath); } catch (Exception ex) { ex.ToString(); // Response.Redirect (strMWRequestBad); //response.write "There was a problem sending the email"; } }
internal static void Send(MailMessage message) { object obj2 = _helper.CreateInstance(); if (message.From != null) { _helper.SetProp(obj2, "From", message.From); } if (message.To != null) { _helper.SetProp(obj2, "To", message.To); } if (message.Cc != null) { _helper.SetProp(obj2, "Cc", message.Cc); } if (message.Bcc != null) { _helper.SetProp(obj2, "Bcc", message.Bcc); } if (message.Subject != null) { _helper.SetProp(obj2, "Subject", message.Subject); } if (message.Priority != MailPriority.Normal) { string str = null; switch (message.Priority) { case MailPriority.Normal: str = "normal"; break; case MailPriority.Low: str = "low"; break; case MailPriority.High: str = "high"; break; } if (str != null) { SetField(obj2, "importance", str); } } if (message.BodyEncoding != null) { object prop = _helper.GetProp(obj2, "BodyPart"); SmtpMail.LateBoundAccessHelper.SetPropStatic(prop, "Charset", message.BodyEncoding.BodyName); Marshal.ReleaseComObject(prop); } if (message.UrlContentBase != null) { SetField(obj2, "content-base", message.UrlContentBase); } if (message.UrlContentLocation != null) { SetField(obj2, "content-location", message.UrlContentLocation); } if (message.Headers.Count > 0) { IDictionaryEnumerator enumerator = message.Headers.GetEnumerator(); while (enumerator.MoveNext()) { SetField(obj2, (string)enumerator.Key, (string)enumerator.Value); } } if (message.Body != null) { if (message.BodyFormat == MailFormat.Html) { _helper.SetProp(obj2, "HtmlBody", message.Body); } else { _helper.SetProp(obj2, "TextBody", message.Body); } } else { _helper.SetProp(obj2, "TextBody", string.Empty); } IEnumerator enumerator2 = message.Attachments.GetEnumerator(); while (enumerator2.MoveNext()) { MailAttachment current = (MailAttachment)enumerator2.Current; object[] args = new object[3]; args[0] = current.Filename; object o = _helper.CallMethod(obj2, "AddAttachment", args); if (current.Encoding == MailEncoding.UUEncode) { _helper.SetProp(obj2, "MimeFormatted", false); } if (o != null) { Marshal.ReleaseComObject(o); } } string smtpServer = SmtpMail.SmtpServer; if (!string.IsNullOrEmpty(smtpServer) || (message.Fields.Count > 0)) { object propStatic = SmtpMail.LateBoundAccessHelper.GetPropStatic(obj2, "Configuration"); if (propStatic != null) { SmtpMail.LateBoundAccessHelper.SetPropStatic(propStatic, "Fields", "http://schemas.microsoft.com/cdo/configuration/sendusing", 2); SmtpMail.LateBoundAccessHelper.SetPropStatic(propStatic, "Fields", "http://schemas.microsoft.com/cdo/configuration/smtpserverport", 0x19); if (!string.IsNullOrEmpty(smtpServer)) { SmtpMail.LateBoundAccessHelper.SetPropStatic(propStatic, "Fields", "http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer); } foreach (DictionaryEntry entry in message.Fields) { SmtpMail.LateBoundAccessHelper.SetPropStatic(propStatic, "Fields", (string)entry.Key, entry.Value); } object obj6 = SmtpMail.LateBoundAccessHelper.GetPropStatic(propStatic, "Fields"); SmtpMail.LateBoundAccessHelper.CallMethodStatic(obj6, "Update", new object[0]); Marshal.ReleaseComObject(obj6); Marshal.ReleaseComObject(propStatic); } } if (HostingEnvironment.IsHosted) { using (new ProcessImpersonationContext()) { _helper.CallMethod(obj2, "Send", new object[0]); goto Label_03C0; } } _helper.CallMethod(obj2, "Send", new object[0]); Label_03C0: Marshal.ReleaseComObject(obj2); }