1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include <utilcls.h>
/*
* txt: message au format texte (utilisé si la messagerie du destinataire ne gère pas le HTML
* html: message au format HTML
* subject: sujet du message
* from: adresse de l'expéditeur
* dest: liste de destinataires (ex: "\"Marc\" <marc@wanadoo.fr>,\"Thierry\" <thierry@wanadoo.fr>")
* smtpserver: adresse du serveur SMTP (ex: smtp.orange.fr)
* pjointe: chemin de la pièce jointe
*/
void TForm1::envoi_mail(char *txt,char *html,char *subject,char *from,
char *dest,char *smtpserver,char *pjointe)
{
Variant cdoM,cdoC,cdoF;
AnsiString cdoURL="http://schemas.microsoft.com/cdo/configuration/";
cdoM = Variant::CreateObject("CDO.Message");
cdoC = Variant::CreateObject("CDO.Configuration");
cdoF = cdoC.OlePropertyGet("Fields");
cdoF.OlePropertySet("Item",(cdoURL + "sendusing").c_str(),2);
cdoF.OlePropertySet("Item",(cdoURL + "smtpserver").c_str(),smtpserver);
cdoF.OlePropertySet("Item",(cdoURL + "smtpserverport").c_str(),25);
cdoF.OleProcedure("Update");
cdoM.OlePropertySet("Configuration",cdoC);
cdoM.OlePropertySet("To",dest);
cdoM.OlePropertySet("From",from);
cdoM.OlePropertySet("Subject",subject);
cdoM.OlePropertySet("TextBody",txt);
cdoM.OlePropertySet("HTMLBody",html);
cdoM.OleProcedure("AddAttachment",pjointe);
cdoM.OleProcedure("Send");
cdoF = Unassigned;
cdoC = Unassigned;
cdoM = Unassigned;
} |
Partager