-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorreo.c
126 lines (101 loc) · 3.04 KB
/
correo.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* prueba */
/* #ifdef A_TOMAR_POR_EL_CULO */
#include "services.h"
#ifdef SMTP
int check_smtp(char buf[BUFSIZE]);
#endif
/**************** enviar_correo *******************************
Esta funcion envia un correo con el email configurado del source k sea
con el subject y body pertinentes al destino indicado.
*************************************************************/
int enviar_correo(const char * destino, const char *subject, const char *body)
{
#ifdef SMTP
int sockmail;
struct hostent *hp;
struct sockaddr_in their_addr;
char buf[1024];
if ((hp=gethostbyname(ServerSMTP)) == NULL)
return 0;
if ((sockmail=socket(AF_INET, SOCK_STREAM, 0)) == -1)
return 0;
their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(PortSMTP);
their_addr.sin_addr = *((struct in_addr *)hp->h_addr);
bzero(&(their_addr.sin_zero),8);
if (connect(sockmail, (struct sockaddr *)&their_addr,sizeof(struct sockaddr)) == -1)
return 0;
sprintf(buf, "HELO localhost\n"
"MAIL FROM: %s\n"
"RCPT TO: %s\n"
"DATA\n"
"From: %s\n"
"To: %s\n"
"Subject: %s\n"
"%s\n"
".\n"
"QUIT\n", SendFrom, destino, SendFrom, destino, subject, body);
if (send(sockmail, buf, sizeof(buf),0) == -1)
return 0;
close(sockmail);
return 1;
}
#endif
#ifdef SENDMAIL
FILE *p;
char sendmail[PATH_MAX];
snprintf(sendmail, sizeof(sendmail), SendMailPatch, destino);
// snprintf(sendmail, sizeof(sendmail), "/usr/sbin/sendmail masakresoft@wanadoo.es");
if (!(p = popen(sendmail, "w"))) {
// privmsg(s_NickServ, u->nick, "mail jodido");
log("mail jodio");
return 0;
}
fprintf(p, "From: %s\n", SendFrom);
fprintf(p, "To: %s\n", destino);
fprintf(p, "Subject: %s\n", subject);
fprintf(p, "%s\n", body);
fprintf(p, "\n.\n");
pclose(p);
// log("Parece que funciona!! - %s - %s - %s", destino, subject, body);
return 1;
}
#endif
#ifdef SMTP
int check_smtp(char buf[BUFSIZE])
{
/** Esta funcion recibe la contestacion k recibimos del smtp y nos
devuelve si se ha producido un erro o no. Caso de ser asi, logea el
error. ***/
char cod[5];
int codigo;
//log("SMTP = %s",buf);
strncpy(cod,buf,4);
//log("strncpy....");
codigo = strlen(cod);
cod[codigo] = '\0';
//log("asignado cod..");
if (cod) codigo = atoi(cod);
else codigo = 500;
//log("Codigo SMTP = %d",codigo);
switch(codigo) {
case 220:
return 1;
break;
case 221:
return 1;
break;
case 250:
return 1;
break;
case 354:
return 1;
break;
default:
log("SMTP ERROR(%d) : %s",codigo,buf);
return 0;
}
return 0;
}
#endif
// #endif /* #ifdef A_TOMAR_POR_EL_CULO */