mar 21, 2010
Enviado por Kalith en .NET, C/C++, Programacion
Enviar emails con Visual C++ .NET
Despues de tiempo sin escribir (ya se me acabaron las excusas asi que no dire otra), pues retomo los menesteres del blog. Realmente el post es bastante sencillo, es una pequeña clase para enviar emails a través de .NET especificamente de visual c++ la cual me toco hacer para un proyecto de la empresa donde trabajo, puede ser portado sin mayor dificultad a c#, vb.NET o cualquier lenguaje que este soportado por el framework.
easysendmail.h
// ===============================================================================
// Leonardo B.
// Filename: easysendmail.h
// Description: A simple class to send mails
// ================================================================================
#pragma once
using namespace System;
using namespace System::Net;
using namespace System::Net::Mail;
ref class Easysendmail{
private:
System::Net::Mail::MailMessage^ message;
System::Net::Mail::SmtpClient^ smtpclient;
System::Net::NetworkCredential^ credentials;
public:
Easysendmail(String^, String^, String^);
void add_recipient(String^);
void add_subject(String^);
void add_body(String^);
void add_server(String^, size_t);
void add_attachments(String^);
void add_attachments(array<String^>^);
void send_mail();
};
easysendmail.cpp
// ===============================================================================
// Filename: easysendmail.cpp
// Description: Implementation of Easysendmail class
// ===============================================================================
#include "stdafx.h"
#include "easysendmail.h"
Easysendmail::Easysendmail(String^ nombre, String^ from, String^ autentification){
message = gcnew MailMessage();
smtpclient = gcnew SmtpClient();
credentials = gcnew NetworkCredential(from, autentification);
message->From = gcnew MailAddress(from, nombre, System::Text::Encoding::UTF8);
}
void Easysendmail::add_recipient(String^ to){
message->To->Add(to);
}
void Easysendmail::add_subject(String^ subject){
message->Subject = subject;
}
void Easysendmail::add_body(System::String ^body){
message->Body = body;
}
void Easysendmail::add_server(String^ host, size_t port){
smtpclient->Port = port;
smtpclient->Host = host;
}
void Easysendmail::add_attachments(String^ attach){
message->Attachments->Add(gcnew Attachment(attach));
}
void Easysendmail::add_attachments(array<String^>^ attach){
for (int i = 0; i < attach->Length; ++i)
message->Attachments->Add(gcnew Attachment(attach[i]));
}
void Easysendmail::send_mail(){
smtpclient->Credentials = credentials;
smtpclient->EnableSsl = true;
smtpclient->Send(message);
}
Posts Relacionados
- Instalar boost en visual studio Todos los rumores eran falsos, ni fuimos encarcelados por gente...
- Enviar correos desde Bash Pues en esta entrada les voy a compartir un pequeño...
- Enviar un correo con Adjunto mediante PHP Como dice el título de la entrada, hoy abarcaremos de...
- Usar una imagen como portada de carpeta en Windows Un tema corto, en Windows existen varias formas de tener...
- C#: Manejo de archivos de texto (I) Buenas Veamos un poco como manejar los ficheros en la...
- C#: Generar md5 Buenas Primero tenemos que tener ciertas inclusiones, tanto la que...
- Cargar un comboBox desde la base de datos en csharp Buenas. Seguimos un poco en la onda de .NET, veamos...
Menciones/Notificaciones
- how to become a stripper - if you go randomly into a crowded... street and start shouting about how great your it services are, people will almost ...



Mmm, waow el .cpp se esta convirtiendo en .net. :O esta evolucionando al lado oscuro. Cada ves eres mas apellido Puertas que antes. Imperialista mismo
PD: El post esta muy bueno, gracias :D
Usandojajaj debo confesar que tengo cierta debilidad por las tecnologías de microsoft.
UsandoBuen post :D me agrado
Usando