コード例 #1
0
 public static bool _Mtd_Email(string _P_Str_Body_, string _P_Str_To_, System.Web.Mail.MailFormat _P_Str_Formato_, string _P_Str_subje_)
 {
     try
     {
         if (UrlIsValid("www.conssa.com"))
         {
             System.Net.Mail.MailMessage _Mail_Email_ = new System.Net.Mail.MailMessage("*****@*****.**", _P_Str_To_);
             _Mail_Email_.Subject = _P_Str_subje_.TrimEnd();
             _Mail_Email_.Body    = _P_Str_Body_.TrimEnd();
             //_Mail_Email_.Body
             //System.Web.Mail.SmtpMail.SmtpServer="http://200.74.224.21";
             //System.Web.Mail.SmtpMail.SmtpServer="200.74.224.21";
             //System.Web.Mail.SmtpMail.SmtpServer="192.168.1.94";
             //System.Web.Mail.SmtpMail.SmtpServer = "200.74.224.21";
             _Mail_Email_.IsBodyHtml = true;
             _Mail_Email_.Priority   = System.Net.Mail.MailPriority.High;
             System.Net.Mail.SmtpClient d = new System.Net.Mail.SmtpClient("mail.cantv.net");
             d.Send(_Mail_Email_);
             //_Mtd_Actualizar(_P_Str_Clave, _P_Str_Tabla, _P_Str_Conexion);
             _Mail_Email_.Dispose();
             return(true);
         }
         else
         {
             return(false);
         }
         //  d.SendCompleted += new System.Net.Mail.SendCompletedEventHandler(d_SendCompleted);
     }
     catch (Exception ou)
     {
         string error = ou.Message.ToString();
         return(false);
     }
 }
コード例 #2
0
        public bool SendEmail(string pSubject, string pBody, System.Web.Mail.MailFormat pFormat, string pAttachmentPath, string pEmailTo)
        {
            try
            {
                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");
                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",
                    "*****@*****.**");
                myMail.Fields.Add
                    ("http://schemas.microsoft.com/cdo/configuration/sendpassword",
                    "espl@notification");
                myMail.Fields.Add
                    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl",
                    "true");
                myMail.From = "*****@*****.**";//[email protected]
                myMail.To   = pEmailTo;
                //myMail.Cc = "*****@*****.**";
                myMail.Subject    = pSubject;
                myMail.BodyFormat = pFormat;
                myMail.Body       = pBody;
                if (pAttachmentPath.Trim() != "")
                {
                    System.Web.Mail.MailAttachment MyAttachment =
                        new System.Web.Mail.MailAttachment(pAttachmentPath);
                    myMail.Attachments.Add(MyAttachment);
                    myMail.Priority = System.Web.Mail.MailPriority.High;
                }

                System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:465";
                System.Web.Mail.SmtpMail.Send(myMail);
                return(true);
            }
            catch (Exception ex)
            {
                // throw;
                return(false);
            }
            finally
            {
                //SendEMail(KeysGlobal.pGmailEmail, KeysGlobal.pTo, pSubject, pBody, pAttachmentPath);
            }
        }
コード例 #3
0
		///////////////////////////////////////////////////////////////////////
		public static string send_email( // 6 args
			string to,
			string from,
			string cc,
			string subject,
			string body,
			System.Web.Mail.MailFormat body_format)
		{
			return send_email(
				to,
				from,
				cc,
				subject,
				body,
				body_format,
				System.Web.Mail.MailPriority.Normal,
				null,
				false);
		}
コード例 #4
0
		///////////////////////////////////////////////////////////////////////
		public static string send_email(
			string to,
			string from,
			string cc,
			string subject,
			string body,
			System.Web.Mail.MailFormat body_format,
			System.Web.Mail.MailPriority priority,
			int[] attachment_bpids,
			bool return_receipt)
		{
            Dictionary<string,int> files_to_delete = new Dictionary<string,int>();
			ArrayList directories_to_delete = new ArrayList();
			System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
			msg.To = to;
			msg.From = from;

            if (!string.IsNullOrEmpty(cc.Trim())) 
            {
                msg.Cc = cc; 
            }
			
            msg.Subject = subject;
			msg.Priority = priority;

			// This fixes a bug for a couple people, but make it configurable, just in case.
			if (Util.get_setting("BodyEncodingUTF8", "1") == "1")
			{
				msg.BodyEncoding = Encoding.UTF8;
			}


			if (return_receipt)
			{
                msg.Headers.Add("Disposition-Notification-To", from);
			}

			// workaround for a bug I don't understand...
			if (Util.get_setting("SmtpForceReplaceOfBareLineFeeds", "0") == "1")
			{
				body = body.Replace("\n", "\r\n");
			}

            msg.Body = body;
			msg.BodyFormat = body_format;


			string smtp_server = Util.get_setting("SmtpServer", "");
			if (smtp_server != "")
			{
				System.Web.Mail.SmtpMail.SmtpServer = smtp_server;
			}

			string smtp_password = Util.get_setting("SmtpServerAuthenticatePassword", "");

			if (smtp_password != "")
			{
				msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = smtp_password;
				msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
				msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] =
					Util.get_setting("SmtpServerAuthenticateUser", "");
			}

			string smtp_pickup = Util.get_setting("SmtpServerPickupDirectory", "");
			if (smtp_pickup != "")
			{
				msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"] = smtp_pickup;
			}


			string send_using = Util.get_setting("SmtpSendUsing", "");
			if (send_using != "")
			{
				msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = send_using;
			}


			string smtp_use_ssl = Util.get_setting("SmtpUseSSL", "");
			if (smtp_use_ssl == "1")
			{
				msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true";
			}

			string smtp_server_port = Util.get_setting("SmtpServerPort", "");
			if (smtp_server_port != "")
			{
				msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = smtp_server_port;
			}

			if (attachment_bpids != null && attachment_bpids.Length > 0)
			{

				string upload_folder = btnet.Util.get_upload_folder();

				if (string.IsNullOrEmpty(upload_folder))
				{
					upload_folder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
					Directory.CreateDirectory(upload_folder);
					directories_to_delete.Add(upload_folder);
				}


				foreach (int attachment_bpid in attachment_bpids)
				{
					byte[] buffer = new byte[16 * 1024];
					string dest_path_and_filename;
					Bug.BugPostAttachment bpa = Bug.get_bug_post_attachment(attachment_bpid);
					using (bpa.content)
					{
						dest_path_and_filename = Path.Combine(upload_folder, bpa.file);

                        // logic to rename in case of dupes.  MS Outlook embeds images all with the same filename
                        int suffix = 0;
                        string renamed_to_prevent_dupe = dest_path_and_filename;
                        while (files_to_delete.ContainsKey(renamed_to_prevent_dupe))
                        {
                            suffix++;
                            renamed_to_prevent_dupe = dest_path_and_filename + Convert.ToString(suffix);
                        }
                        dest_path_and_filename = renamed_to_prevent_dupe;

                        // Save to disk
						using (FileStream out_stream = new FileStream(
							dest_path_and_filename,
							FileMode.CreateNew,
							FileAccess.Write,
							FileShare.None))
						{
                            int bytes_read = bpa.content.Read(buffer, 0, buffer.Length);
							while (bytes_read != 0)
							{
								out_stream.Write(buffer, 0, bytes_read);

								bytes_read = bpa.content.Read(buffer, 0, buffer.Length);
							}
						}

					}

                    // Add saved file as attachment
					System.Web.Mail.MailAttachment mail_attachment = new System.Web.Mail.MailAttachment(
						dest_path_and_filename,
						System.Web.Mail.MailEncoding.Base64);
					msg.Attachments.Add(mail_attachment);
                    files_to_delete[dest_path_and_filename] = 1;
				}
			}


			try
			{
                // This fixes a bug for some people.  Not sure how it happens....
                msg.Body = msg.Body.Replace(Convert.ToChar(0), ' ').Trim();
                System.Web.Mail.SmtpMail.Send(msg);

				// We delete late here because testing showed that SmtpMail class
				// got confused when we deleted too soon.
				foreach (string file in files_to_delete.Keys)
				{
					File.Delete(file);
				}

				foreach (string directory in directories_to_delete)
				{
					Directory.Delete(directory);
				}

				return "";
			}
			catch (Exception e)
			{
				Util.write_to_log("There was a problem sending email.   Check settings in Web.config.");
				Util.write_to_log("TO:" + to);
				Util.write_to_log("FROM:" + from);
				Util.write_to_log("SUBJECT:" + subject);
				Util.write_to_log(e.GetBaseException().Message.ToString());
				return (e.GetBaseException().Message);
			}

		}