Crie uma aplicação C# e coloque 4 componentes txt(renomei respectivamente para txtServidorSmtp, txtRemetente, txtDestinatario, txtAssunto e um componente de texto com o nome txtTexto). Pronto, agora é só seguir o código abaixo:
//Definindo Remetente
MailAddress endRemetente = new MailAddress(txtRemetente.Text);
//Definindo Destinatário
MailAddress endDestinatario = new MailAddress(txtDestinatario.Text);
//Definindo Email
MailMessage msg;
msg = new MailMessage(endRemetente, endDestinatario);
msg.Subject = txtAssunto.Text;
msg.Body = txtTexto.Text;
//Definindo Envio
SmtpClient smtp = new SmtpClient(txtServidorSmtp.Text);
smtp.Send(msg);
Quer aprender Delphi for PHP?
Caros amigos delphianos, estão com dificuldades em encontrar um bom material sobre Delphi for PHP? Visite a Comunidade Delphi so PHP e veja algumas notícias sobre as novas tendências desta ferramenta. Lá você vai encontrar dicas, downloads, artigos, videos e muito mais sobre o Delphi for PHP. Para se cadastrar é muito simples, rápido e seguro. Clique aqui e seja o mais novo membro da Comunidade Delphi so PHP e bons estudos.
No mais até a próxima.
No mais até a próxima.
quarta-feira, 27 de agosto de 2008
Criando uma classe de conexão no C#
Abaixo uma classe de conexão bem simples...
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace Persistencia
{
public static class Banco
{
public static OleDbConnection conexao = new OleDbConnection();
public static void AbrirConexao()
{
conexao.ConnectionString = @"Aqui fica a string de conexão";
conexao.Open();
}
public static void FecharConexao()
{
if (conexao.State == ConnectionState.Open)
{
conexao.Close();
conexao.Dispose();
}
}
public static void ExecutarComando(string textoComando)
{
if (conexao.State != ConnectionState.Open)
{
AbrirConexao();
}
OleDbCommand comando = new OleDbCommand();
comando.CommandText = textoComando;
comando.Connection = conexao;
int registrosAfetados = comando.ExecuteNonQuery();
}
public static OleDbDataReader SelecionarRegistros(string textoComando)
{
if (conexao.State != ConnectionState.Open)
{
AbrirConexao();
}
OleDbCommand comando = new OleDbCommand();
comando.CommandText = textoComando;
comando.Connection = conexao;
return comando.ExecuteReader();
}
public static OleDbDataReader SelecionarUmRegistro(string textoComando)
{
if (conexao.State != ConnectionState.Open)
{
AbrirConexao();
}
OleDbCommand comando = new OleDbCommand();
comando.CommandText = textoComando;
comando.Connection = conexao;
return (OleDbDataReader)comando.ExecuteScalar();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace Persistencia
{
public static class Banco
{
public static OleDbConnection conexao = new OleDbConnection();
public static void AbrirConexao()
{
conexao.ConnectionString = @"Aqui fica a string de conexão";
conexao.Open();
}
public static void FecharConexao()
{
if (conexao.State == ConnectionState.Open)
{
conexao.Close();
conexao.Dispose();
}
}
public static void ExecutarComando(string textoComando)
{
if (conexao.State != ConnectionState.Open)
{
AbrirConexao();
}
OleDbCommand comando = new OleDbCommand();
comando.CommandText = textoComando;
comando.Connection = conexao;
int registrosAfetados = comando.ExecuteNonQuery();
}
public static OleDbDataReader SelecionarRegistros(string textoComando)
{
if (conexao.State != ConnectionState.Open)
{
AbrirConexao();
}
OleDbCommand comando = new OleDbCommand();
comando.CommandText = textoComando;
comando.Connection = conexao;
return comando.ExecuteReader();
}
public static OleDbDataReader SelecionarUmRegistro(string textoComando)
{
if (conexao.State != ConnectionState.Open)
{
AbrirConexao();
}
OleDbCommand comando = new OleDbCommand();
comando.CommandText = textoComando;
comando.Connection = conexao;
return (OleDbDataReader)comando.ExecuteScalar();
}
}
}
Assinar:
Postagens (Atom)
