nramesh30
asked on
Sendmail
How do I send mail from my application to a group of people. I guess that I could use sendmail. How do I program sendmail to achieve this task ? I don't have much idea about sendmail
ASKER
The user list to whom I have to send mail to , will be generated in my application. How do handle this situation ? I heard that sendmail would be very flexible to use for my case.
Try this:
FILE *sendmail = popen("/usr/lib/sendmail -t");
if(sendmail)
{
fprintf(sendmail, "To: %s, %s, %s\n", user[0], user[1], user[2]);
fprintf(sendmail, "From: who@where.com\n");
fprintf(sendmail, "Subject: test\n\n");
fprintf(sendmail, "Body");
}
close(sendmail);
FILE *sendmail = popen("/usr/lib/sendmail -t");
if(sendmail)
{
fprintf(sendmail, "To: %s, %s, %s\n", user[0], user[1], user[2]);
fprintf(sendmail, "From: who@where.com\n");
fprintf(sendmail, "Subject: test\n\n");
fprintf(sendmail, "Body");
}
close(sendmail);
ASKER
thanks guys. that works perfectly fine. Is it possible to hide the user list to be shown up on the To field in the mail. Is it possible to program in such a way that the To field shows some thing like 'To undisclosed recipeints'
Thanks
Thanks
ASKER
thanks guys. that works perfectly fine. Is it possible to hide the user list to be shown up on the To field in the mail. Is it possible to program in such a way that the To field shows some thing like 'To undisclosed recipeints'
Thanks
Thanks
ASKER
thanks guys. that works perfectly fine. Is it possible to hide the user list to be shown up on the To field in the mail. Is it possible to program in such a way that the To field shows some thing like 'To undisclosed recipeints'
Thanks
Thanks
ASKER
thanks guys. that works perfectly fine. Is it possible to hide the user list to be shown up on the To field in the mail. Is it possible to program in such a way that the To field shows some thing like 'To undisclosed recipeints'
Thanks
Thanks
Bcc:
You can do this using perl to. The answer above in C is fine, but this includes all your options
#!/usr/bin/perl
$to = 'someone@somewhere.com';
@hidden_recipients('guy1@c ompany.one ','guy2@co mpany.one' );
open(SENDMAIL, "sendmail -t|");
print SENDMAIL, "To: $to", "\n";
print SENDMAIL, "Bcc: ", join(",",@hidden_recipient s), "\n";
print SENDMAIL, "--------", "\n";
print SENDMAIL <<EOF
Hey,
This is an email I am sending you.
Later.
EOF
close(SENDMAIL);
exit;
OR YOU CAN ADD THE BCC PART TO THE C CODE FROM ABOVE
FILE *sendmail = popen("/usr/lib/sendmail -t");
if(sendmail)
{
fprintf(sendmail, "To: %s, %s, %s\n", user[0], user[1], user[2]);
fprintf(sendmail, "Bcc: %s, %s, %s\n", user[0], user[1], user[2]);
fprintf(sendmail, "From: who@where.com\n");
fprintf(sendmail, "Subject: test\n\n")
fprintf(sendmail, "Body");
}
close(sendmail);
#!/usr/bin/perl
$to = 'someone@somewhere.com';
@hidden_recipients('guy1@c
open(SENDMAIL, "sendmail -t|");
print SENDMAIL, "To: $to", "\n";
print SENDMAIL, "Bcc: ", join(",",@hidden_recipient
print SENDMAIL, "--------", "\n";
print SENDMAIL <<EOF
Hey,
This is an email I am sending you.
Later.
EOF
close(SENDMAIL);
exit;
OR YOU CAN ADD THE BCC PART TO THE C CODE FROM ABOVE
FILE *sendmail = popen("/usr/lib/sendmail -t");
if(sendmail)
{
fprintf(sendmail, "To: %s, %s, %s\n", user[0], user[1], user[2]);
fprintf(sendmail, "Bcc: %s, %s, %s\n", user[0], user[1], user[2]);
fprintf(sendmail, "From: who@where.com\n");
fprintf(sendmail, "Subject: test\n\n")
fprintf(sendmail, "Body");
}
close(sendmail);
ASKER
Thanks ijduggan,
Can I write a program which reads all the email addresses from a flat file and send emails to all of them simultaneously using sendmail ?
Can I write a program which reads all the email addresses from a flat file and send emails to all of them simultaneously using sendmail ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's wonderful. But i'am not a Perl person . what does chop and $_ do ? how do I do this in C?
It would be much easier to answer your question if you would be more specific about your needs... C is pretty much the same. All you have to do is read the values off stdin or a from a file and use the C code above to send it. If you want to read the names from a file, look to the man pages if you don't know file io in C.
man fopen
man fdopen
STDIN would be the file descriptor you need.
man fopen
man fdopen
STDIN would be the file descriptor you need.
ASKER
Instead of sending mail to the email addressess in the list ONE BY ONE, is it possible to send a bulk email simultaneously, at a time to al the recipients ?
some thing like
sendmail < listofrecipeints
some thing like
sendmail < listofrecipeints
FILE *mail = popen("/usr/bin/mail user1 user2 user3", "w");
if (mail) {
fprintf(mail, "Subject: a report\n\n");
fprintf(mail, "all ok.\n");
pclose(mail);
}