티스토리 뷰

대용량 메일링 sendmail+PHP4.2 CLI
mass large mailing sendmail PHP

별도 메일 서버 구축으로 하루 10-20 만개 이상 메일 보내기

ram: 512 or 1G 정도
CPU: 팬4 1G 정도
PHP버전: 4.2.x 이상
Sendmail 버전: 8.12.x 이상
파일시스템: 저널링(ext3 or 다른것들 )

=================================================

# php -q mail_sender1.php
1h1]@Z <ehdgns777@@nexonclub.com>... Invalid route address
Syntax error in mailbox address "cccvcc@??????.com" (non-printable character)
Syntax error in mailbox address "5??dake1004@hanmir.com" (non-printable character)
@eGQ:{ <ky5640@.dreamwiz.com>... Invalid host name
9i<:Hl <www.qortnqorwh.@.yahoo.co.kr>... Invalid host name
kr>... Unbalanced '>'
1h@N?l <okm542588@yahoo.co,kr>... Unbalanced '<'
1h@N?l <okm542588@yahoo.co... Unbalanced '<'
kr>... Unbalanced '>'
kr>... Unbalanced '>'
1h@N?l <okm542588@yahoo.co,kr>... Unbalanced '<'
kr>... Unbalanced '>'
1hEB>g <tayure@.naver.com>... Invalid host name
A$0\?n <kumsimwarez@.com.ne.kr>... Invalid host name
@LAv?u <scmi@tood@toodent.com>... Invalid route address
Syntax error in mailbox address "k8983@??????.com" (non-printable character)
죽었음

--------------------------------------------------------------
<?php
//php -q mail_sender1.php
$code=1;

// limit 6만,-1
$filename = "/home/mailing/homepage/mailing/up/esp_all.txt";
$newfile = file($filename);

$nums=count($newfile);

//print $nums; exit;

//메일 로그
$filename_log = "/home/mailing/homepage/mailing/up/esp_logs.txt";
$newfile_log = fopen($filename_log, "a") or die("파일을 만들 수 없습니다.");


        for ($k=0;$k<$nums;$k++){
                $newfiles=explode("_T_",$newfile[$k]);

                $id=$newfiles[0];
                $email=$newfiles[1];
                $name= $newfiles[2];
                $year=$newfiles[3];

                //print "$id,$email,$name,$year \n";

                $to  = "$name <$email>"; // 콤마로 여러명에게
                $subject="[에스피리드 온라인] 이벤트 뉴스레터입니다.";

                include "up/esp20031210.php";

                $from="help@toodritu-online.com";

                $headers  = "MIME-Version: 1.0\r\n";
                $headers .= "Content-type: text/html; charset=euc-kr\r\n";
                $headers .= "From: 에스피리드 <$from>\r\n";
                if(isset($email) && (strlen($email)>8)){
                    //set_time_limit(150);
                    mail($to, $subject, $message, $headers,"-f$from");
                }

                if(($code%101)==0){// 연기된 메일은 가차없이 지운다 !
                        $content=$email."\n";
                        print $content."\n";
                        @fwrite($newfile_log, $content) or die("파일에 내
용을 넣을 수 없습니다.");    
                        sleep(2);
                        shell_exec("rm -rf /var/spool/mqueue/q*/*; /etc/rc.d/init.d/sendmail restart;");
                        sleep(8);
                }

                $code++;
  }

fclose($newfile_log);
?>


deferred 된 메일은 가차없이 지운다.
큐에 쌓일 경우 ram이 부족해서 Sendmail 이 반응하지 않는다.
큐에 100개가 쌓일 경우 지우기

ram 512 나, 팬4 정도된다면 큐에 1000-2000천개 정도 ?

외국 포럼을 봐도 큐를 지우는 것이 가장 효과적이라는 말들이 많다...?
큐에 메일이 1000천개 정도 쌓이면, 메모리도 많이 차지하고,
차라리 지우는 것이 다음 메일 발송을 위해 효과적이다!!!

네트웍이 안좋아 연결이 느린 메일 서버일 경우에도 메일이 큐에 쌓이게 되는데,
이 경우는 그냥 포기 하는게..--;
그것 외에 큐에 쌓이는 것은 거의 대부분 나중에도 보내지지 않는 deferred 된 메일 들이므로 신경 안써도 될
듯..

큐가 1000개 넘었을 경우에 지웠더니 PHP실행시간 초과 메시지가 5000천개 정도 발송되니뜨고,
>Fatal error</b>:  Maximum execution time of 30 seconds exceeded in
<b>/home/mailing/homepage/mailing/mail_sender3.php</b>
100개가 좋은 듯 !!

그 담에도 뜨면 10개로 !!
그담에도 뜨면 sendmail을 제외한 아파치 등의 서버 프로그램 프로세스 죽이고 !

아흐 mmx --;



--------------------------------------------------------------
메일주소가 한글이라 오류가 발생하지만, 다음 메일은 메일을 발송한다.

php -q mail_sender2.php
Syntax error in mailbox address "sukhoi@????.com" (non-printable character)
--------------------------------------------------------------
메일주소가 다음과 같이 콤마(,)일 경우 오류 발생시킨다. sukhoi@empal,com

com>... Unbalanced '>'
@L?59+ <sukhoi@empal,com>... Unbalanced '<'
@L?59+ <sukhoi@empal... Unbalanced '<'
com>... Unbalanced '>'
com>... Unbalanced '>'
@L?59+ <sukhoi@empal,com>... Unbalanced '<'
com>... Unbalanced '>'
--------------------------------------------------------------
다음과 같이 오류 발생 시킴
@L?59+ <sukhoi@.empal.com>... Invalid host name

--------------------------------------------------------------
scmi@tood@toodent.com 다음과 같이 오류
@LAv?u <scmi@tood@toodent.com>... Invalid route address

--------------------------------------------------------------
메일주소에 한글이 있거나, 골뱅이(@)가 1개 이상일 경우나, 마침표외에 콤마 일 경우.
메일주소에서 영문하고, 골뱅이,점만 가능해야 한다. 글구 골뱅이와 쩜은 1개여야 한다.

--------------------------------------------------------------
sukhoi@empalfdkdfodfk90.com 도메인이 틀릴 경우는 오류발생하지 않음

--------------------------------------------------------------

메일링 로그 - procmail , sendmail

이 처방전은 제목이 test인 메일만 로그를 남기는 처방입니다. 모든 메일에 대해 로그를 남기고 싶으시면

* ^Subject:.*

와 같이 바꾸시면 됩니다.
그리고 $SENDMAIL -oi -f와 같이 f옵션을 사용하면 "X-warning....."라는 경고메세지가 쌓이게 됩니다. f옵션은
센드메일이 보내는 사람의 주소를 envelope가 아닌 command line에서 읽어들이도록 하는 옵션이다. 이렇게 되면
전송하는 메일이 가짜메일가능성이 있다는 점에서 경고메세지가 나옵니다.


=================================================
Sendmail.cf 파일


# minimum time in queue before retry
# 메일 전송 실패 할 경우 큐에 저장한 후에 30분 후에 재 전송
O MinQueueAge=30m

# how many jobs can you process in the queue?
# 큐에서 1번에 보낼 수 있는 메일 수
O MaxQueueRunSize=10000

파일 시스템 최소 여유공간 늘리기
O MinFreeBlocks=4000

메일 용량 늘리기 기본 10메가
#O MaxMessageSize=1000000

=================================================

--------------------------------------------------------------
대량 메일 발송 일 경우에 100명 마다 파일에 기록 !
100명 한테 메일 보내고 성공 OK 메시지 기록


--------------------------------------------------------------
아래가 로그 파일 입니다. 로그 파일을 보면 메일 보내기 실패 원인- 받기 실패 원인을 알 수 있습니다.
보내기가 안될 경우 로그 파일을 카피 해서 그 부분만 올려 주세요.
# vi  /var/log/maillog

# vi  /var/log/maillog.1

# vi  /var/log/maillog.2
--------------------------------------------------------------
썬 서버 메일 로그

/var/log/syslog and /var/adm/messages

--------------------------------------------------------------
메일로그 분석

내 DNS가 틀렸을 경우
stat=Deferred: Connection reset by smtp.sayclub.com.

메일 보내짐. 큐에 쌓여 있으나, 성공적으로 보내졌는지는 알지 못함 !
stat=Sent (hBF2Cq4O006059 Message accepted for delivery)

Deferred로 된것은 메일 발송 실패 !
stat=Deferred: Connection timed out with a.mx.naver.co.kr

stat=Deferred: 450 mailbox full

stat=Deferred: 451 <root@localhost.localdomain> unable to verify address

stat=Deferred: Connection refused by hanir.com.

stat=User unknown

stat=Deferred: 450 <root@localhost.localdomain>: Sender address rejected: Domain not found




mymylife0508@sayclub.com

5천개 발송하고 죽은듯 !

파일을 5천개 씩 나눠서 발송 해라 !


=================================================
[mailing@localhost mailing]$ date
2003. 12. 15. (월) 12:13:47 KST
[mailing@localhost mailing]$ php -q mail_sender3.php
5200개 발송 시작 !



=================================================
네이버,엠팔,다음,네띠앙,코리아닷컴,네이트,심마니,세이클럽 가입하고 발송 테스트


=================================================
회원가입 란에 메일 주소 예제가 있을 경우 카피 하는 회원 많음.
tood@toodent.com

=================================================
한글 메일 주소 종종 있음
ssss@다음.net
ssss@세이클럽.com

=================================================
회원가입 DB의 메일주소와 ID를 파일로 넣어라 !
저널링 파일 시스템이 아닐 경우 2천명 씩,
저널렁 파일 시스템일 경우는 5천명씩.

5천명의 기록을 저장한 파일 10.txt, 11.txt , 12.txt 파일을 차례로 읽어서 발송하도록 할 것 !
RAM이 허락 하고, 저널링 파일 시스템이고, 멀티플 큐 일 경우 통으로 보내도 가능
512메가나 1G 정도의 램일 경우
=================================================

웹서버 말고, 당근 별도의 메일 서버 필요

=================================================
멀티플 큐 sendmail.cf ★
저널링 파일 시스템일 경우에만 가능 !
O QueueDirectory=/var/spool/mqueue/q*


# cd /var/spool/mqueue
# mkdir q1 q2 q3 q4 q5 q6
# chown root.mail q*


# /etc/rc.d/init.d/sendmail restart


=================================================


=================================================
★ PHP 버전 최소 PHP4.2 이상

./configure시에 --enable-cli 옵션을 주어야 가능 !
PHP4.3은 기본 설치 됨 !

http://www.php.net/manual/en/features.commandline.php

rpm 4.2 버전에서 된다.

http://www.php.net/manual/en/features.commandline.php


-q             Quiet-mode.  Suppress HTTP Header output.
HTTP 헤더 출력을 억제한다.

-a 동적으로 실행- 헤더 출력 됨 !


[mailing@localhost mailing]$ php -a testx.php
Interactive mode enabled

X-Powered-By: PHP/4.2.2
Content-type: text/html

[mailing@localhost mailing]$ php testx.php
X-Powered-By: PHP/4.2.2
Content-type: text/html


쉘로 짜도 헤더 출력 됨 !

PHP 실행시간 100초 정도로 늘리기


=================================================
큐 상태 보기
# mailq

메일 큐 지우기. sendmail 중지하고, /var/spool/mqueue 아래 큐 디렉토리 들어가서 rm -rf *으로 모두 지우고,
sendmail 재 시작


메일 상태 보기
# mailstat
=================================================

<b>Fatal error</b>:  Allowed memory size of 8388608 bytes exhausted (tried to allocate 262144 bytes) in
<b>/

오류

php.ini 에서 memory_limit  옵션 늘려주어야 함 !

파일 크기가 너무 클 경우에 나오는 에러 !

=================================================
mail() 사용, fsockopen() 사용 ,popen() 사용, socket_connect() 사용

메일서버가 다른 서버라면 소켓 연결 해야 함.

=================================================
다른 전략 3: 숨은 참조(BCC)를 무자게 크게 해서 보내라
전략 4: bulk_mailer 프로그램을 사용해라


=================================================


Lots of stuff to tune -

[1] Speed up your filesystem.  In fact getting yourself a set of
ramdisks (especially those new ones with battery backup) and using
them should speed things up.

[2] Multiple queues, spread across multiple spindles.  Use qtool.pl
heavily - to move outbound mail that gets delayed to backup queues -
and later to fallback hosts which will take over delivery.  Have one
general "dustbin" host as a last resort, where undeliverables
accumulate, are looked at / acted upon [to resolve stuff like
nonexistent domains which have had their MX removed, ISPs which have
dropped you into their border routers ...]

[3] Local caching nameserver

[4] FEATURE(`nocanonify') and a few other things set in your sendmail
config should also help.

[5] Serializing mail delivery, sorting it according to domain ... and
switching to sendmail 8.12.x (which supports pipelining) should also
help you a lot.

[6] Use VERP as much as possible - and split your mail functions
(outbound, inbound, bounce processing etc) across multiple machines.
Have some kind of load balancer - and make sure you process bounces at
the same (or nearly so) rate as you send out mail.  You don't do that,
you run the risk of being blocked by assorted ISPs for overloading
their mail systems with bounces.

There's lots more, but this should do for starters I guess :)

        -srs
=================================================

1:  Upgrade to sendmail-8.12.x (8.12.3 is current).  It is
    a little more efficient, because it does not fork() after
    MAIL.

2:  If you are using large mailing lists, then use the envelope
    splitting capabilities of 8.12.x

3:  Use FEATURE(`nocanonify') to reduce DNS lookups.

4:  Mount the disk partition containing /var/spool/mqueue with
    logging.  This increases solaris disk throughput.
=================================================
Thanks Claus I'm getting there but I've searched the Internet for
these defines...
ESMTP_MAILER_QGRP
confSPLIT_ACROSS_QUEUEGROUPS
etc but unfortunately found nothing.

I've read the TUNING text and the Sendmail Installation and operation
guide section 2.3.1 "Queue Groups and Queue Directories" but I'm still
puzzled.

Each individual address has its own domain i.e. each mail is to a
separate server (500 servers) so I cannot split the queue depending on
the domains.

I've created 4 queue dirs mqueue/q0 mqueue/q1 mqueue/q2 mqueue/q3 and
utilise these already using simply:
define(`QUEUE_DIR',`/var/spool/mqueue/q*')dnl
Indeed by default sendmail places mails randomly into a queue and from
the section 2.3.1 I understand this is the default "mqueue".

How do I define that this default "mqueue" should split large mails
with more than 10 recipients (r=10), what statement ?
and will it then automatically split such mails over all 4 queues ?

Thanks in advance and I hope this will lay down answers for future
Internet searches :-)

=================================================
추천 사이트
http://www.shub-internet.org/brad/papers/sendmail-tuning/

http://tunelinux.pe.kr/sysadmin/iskim/linux-window-7.html
=================================================
갑자기 실행시간 에러 메시지가..
Maximum execution time of 30 seconds exceeded in <b>/home/mailing/homepage/mailing/mail_sender3.php</b>
on line <b>27</b><br />

mail() 함수에서 발생한 오류

2시간만에...흠...ㅋㅋ

메일 큐에 1000개가 쌓이니까 더이상 전송이 안되는 군...ㅋㅋㅋ

1시간이 넘었는데 메일큐의 메일 들이 안갈 경우 모두 삭제 !

메일을 6천개 정도 테스트로 발송 한후 큐에 1000개 정도 쌓일 경우
메일 발송 파일을 6천개로 분리하는 것이..

O MaxQueueRunSize=10000 1만이라고 해도, 큐에 1천개가 쌓일 경우 버벅거림.
시스템이 워낙 꼬져서리...--; 시스템 좋으면 문제 없음.

그러나 잘못된 메일주소 거나, 메일박스가 꽉찼을 경우 문제됨.
정상적인 메일 주소일 경우 5천통 보내는데 1시간 걸린다면,
잘못된 메일 주소가 2-30%정도만 있어도 2시간 정도 걸림...--;


자신의 메일주소로 1-2만개 정도 메일링 주소를 만들고,  
발송테스트 해서 메일큐에 얼마나 쌓이는지 반드시 테스트

1시간이 지났는데도 메일을 모두 발송하지 못했을 경우
메일큐에 많이 남았을 경우
메일링 주소 파일을 더 적게 생성 해야 함.

우왕...짭 128 메가 서버라 5천개 발송하는데 2시간..
1천개는 큐에...미치..

5000개 보내면, 4000개 갑니다. 1000개는 큐에서 거의 죽어 있고..--;
1000개 정도는 다시 반송될 듯 하고...ㅋㅋ

=================================================
mime 리턴패스 설정

$from="help@tood.net";

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=euc-kr\r\n";
$headers .= "From: tood <$from>\r\n";
mail($to, $subject, $message, $headers,"-f$from");

=================================================

rm -rf /var/spool/mqueue/q*/*

/etc/rc.d/init.d/sendmail restart


=================================================
MaxDaemonChildren RefuseLA

#crontab -e
*/15 * * * * /usr/sbin/sendmail -L sm-msp-queue -Ac -q


=================================================

mailq |grep "9420 Sat" |awk '{ print $1}' |while read name
do
mv [qdx]f$name ../spam/
done

This will move all mails of size 9420 arriving on Saturday to a new
location (/var/spool/spam/). Then do:

cd ../spam
mailq -OQueueDirectory=. |less


=================================================
sendmail Deferred queue delete

defer :뜻:(delay) 미루다. 연기하다.

메일큐에서 Deferred 된 큐 삭제 ?

grep


MDeferred: Connection timed out with rcvmail3.nexonclub.com
타임 아웃된 큐는 그냥 놔두고 ?



HERE:
#!/bin/sh
###
### Pour LISTER les queues bloquees par le serveur/operateur "baduser"
passe en argument
###
###
###
###
if [ $# -lt 1 ]
then
echo "\n\n Liste OU Met en Quarantaine OU Expulse les queues
bloquees."
echo "\n\nUsage: "$0" NomDeLOperateurBloque [expulse|attend]"
echo "\n\nFichiers nettoyables actuellement :\n\n"
egrep '^MDeferred: ' /u/var/spool/mqueue/qf*|awk '{print $1}' FS=':'|wc -l
exit 1
fi

if [[  $# -gt 1  &&  $2 == attend ]]
then
echo "QUARANTAINE DEMANDEE !"
egrep '^MDeferred: ' /u/var/spool/mqueue/qf*|grep $1|awk
'{lt=split($1,toto,"/");titi=toto[lt];sub(/^./,"?",titi);kommando="mv
/u/var/spool/mqueue/"titi" /u/var/DEFERRED";system(kommando);}' FS=':'
else
if [[  $# -gt 1  &&  $2 == expulse ]]
then
echo "EXPULSION DEMANDEE !"
egrep '^MDeferred: ' /u/var/spool/mqueue/qf*|grep $1|awk
'{lt=split($1,toto,"/");titi=toto[lt];sub(/^./,"?",titi);kommando="rm
/u/var/spool/mqueue/"titi;system(kommando);}' FS=':'
fi
echo "Listage des expulsables :"
egrep '^MDeferred: ' /u/var/spool/mqueue/qf*|grep $1|awk
'{lt=split($1,toto,"/");titi=toto[lt];sub(/^./,"?",titi);kommando="ls -l
/u/var/spool/mqueue/"titi;system(kommando);print "Erreur: " $3 $4 $5 $6 $7
$8 $9 "\n"}' FS=':'
fi

=================================================


메일을 일정량 이상 발송하면 그 후로는 sendmail이 작동하지 않는다.
php 실행시간문제? 2시간 정도는 잘가는데?

대략 5천통 이상 발송하면, 메일큐를 삭제 하고, sendmail 을 다시 시작해도 바로는 되지 않는다.
php가 문제 인것 같기도 하고.

php파일을 여러개로 분리하거나, cron 에 등록 하거나?
php에서 파일을 열때 메모리가 부족하여 파일을 못열어서, sendmail 로 메일을 못보내는 것 처럼 인식이 되는 것
인가 ?
그럴 수도..


ps -aux|grep sendmail
root       767  0.0  1.9  6144 2524 ?        S    21:40   0:00 [sendmail]
smmsp      776  0.0  1.7  5924 2248 ?        S    21:40   0:00 [sendmail]
root      1094  0.0  0.5  4592  640 pts/2    S    23:26   0:00 grep sendmail

음..오후 4시 50분에 발송한 php는 없는데.. 아래 프로그램이 6메가의 메모리를 잡고 있다..--;
ps -aux|grep php
root      1206  0.1  3.7 16348 4744 pts/0    T    16:54   0:30 php -q mail_sender3.php


아무래도 php문제인듯 하군..

내가 밤 7시에 보낸녀석은 죽은듯. 그러니까 php 실행 시간 오버로..
php에서 파일 큰 것을 20개를 부르는 프로그램이라..

1개를 부를 때는 상관 없는데, 다른 것을 부를 경우에 메모리를 사용하므로,
계속적으로 메모리를 잡고 있는 것이 되므로, 오류가 나며, 그것으로 실행시간 오버 가 된다.

우선 그럼 cron 에 3개 정도의 파일을 등록해 놓고 실행시켜 보도록 하자.

memory_limit=8 메가가 디폴트인데, 이 메모리는 ram에서 차지 하는 메모리
php cli로 프로그램을 실행할 경우에 1메가 정도 되는 파일을 부르더라도, 8메가 정도 차지하게 된다.
ps -aux해서 보면 볼 수 있다. php 데몬과 파일과 프로그램 크기가 모두 포함되기 때문이다.

만약 10메가 되는 파일을 php에서 실행하게 하려면 memory_limit는 30메가는 되어야 할 것이다.
또는 20메가 이상.

PHP에서 큰 파일을 여러개 부를 경우 메모리 제한 오류가 발생 할 수 있으므로,
PHP에서 for문을 사용하지 말고, 파일을 나누어라 !

파일을 나누지 말고,
memory_limit를 최대로 올리고 한번에 보내라 !!! 되도록이면 email,id,가입일이 들어가 있는 파일을
1개로 만들어서, 1번에 발송해라 !!

memory_limit=16 메가 일 경우 최대 5메가 크기의 파일을 PHP에서 열 수 있다.
(PHP CLI 작동할 경우 . # ps -aux로 mem 체크 )

큐에 쌓인 것은 100개 이상 일 경우 자동 삭제 되도록 cron  에 등록 한다 !
큐에 쌓인 것은 버린다. 워낙 꼬진 시스템이라..--;

메이저 도모나 벌크 메일을 써야 하는가?
우선 email 주소 부터 다시 정확하게 수집하는 것이 좋을 것 같다.

잘못된 메일로 메일을 전송하다가 실패하는 것 같다.
30% 이상 느려짐 !!!


----------------------------------------------------------

vi /var/log/maillog 로그 파일이 클 경우
/var 파티션이 풀 났을 경우 df 명령으로 체크

/var/log/maillog 파일은 지울 경우 재부팅

----------------------------------------------------------
sendmail.cf

1초당 최대 연결 수
ConnectionRateThrottle=3

sendmail 프로세스가 24개를 넘으면 큐에 저장.나중에 전송(디폴트가 24개 )
QueueLA=24

sendmail 프로세스가 24개면 sendmail 접속 거부
RefuseLA=24

1번에 생길 수 있는 최대 프로세스 수( sendmail 데몬 최대 수. 메모리가 클 경우 늘려줘라. 1개당 2-4메가 정
도 차지 )
MaxDaemonChildren=256
512메가 정도면 64정도가 적당.

----------------------------------------------------------
256-512 메가 일 경우
O QueueLA=8
O RefuseLA=16
O MaxDaemonChildren=128
O ConnectionRateThrottle=0

mail을 보낼 경우 상대방 DNS를 쿼리 해야 하는 시간도 필요하므로,
DNS 쿼리 타임도 항상 생각 해야 한다.

그리고 내 dns 경우도 되도록이면, 별도의 다른 도메인을 사용하는 것이 좋다.
----------------------------------------------------------

PHP CLI를 사용하고 반드시 cron 에 등록하는 것이 좋다.
그렇지 않을 경우 실행한 컴퓨터를 끄지 못할 수 있다.--;
끌 경우 실행이 취소 되므로.
----------------------------------------------------------

sendmail 튜닝
http://people.freenet.de/slgig/op_en/tuning.html

----------------------------------------------------------

MaxDaemonChildren RefuseLA large 검색


----------------------------------------------------------
악성 email 주소 --
suhoi@,naver.com
suhoi@.naver.com
suhoi@,naver,com
suhoi@naver@naver.com
suhoi@8990.com
suhoi@네이버.com
@yahoo.co.kr
wlgns22@.co.kr
wlgns22@@.co.kr
dwlgns@.net
iller@yahoo..co.kr
aktmxk@ths...alsdnt
123@123.123

@@ -> @
@. -> 부적격
..-> 부적격


$email1=explode("@",$email);
strlen($email1[0])<4 -> 부적격 // 아뒤
strlen($email1[1])<2 -> 부적격 // @@ 일 경우
$email2=explode(".",$email1[1]);
strlen($email2[0])<2 -> 부적격 // @. 일 경우
strlen($email2[1])<2 -> 부적격 // .. 일 경우



----------------------------------------------------------

>Hello
>Trying to send a html email to 5000 people on a list
>Keep getting Fatal error: Maximum execution time of 30 seconds exceeded
>Any pointers on the best way to achieve this lengthily operation without
>the script failing? Best regards Scott
>
If the email is the same for all people on the list (i.e. not
customised) then use the CC field and don't send 5000 emails. If they
are customised then I'd recommend you queue them (fast) rather than wait
whilst they are actually sent (normal). This can be done with sendmail
and qmail, I assume other MTAs too. If you can't queue the emails then
perhaps use cron (or at) to send them outside of a web page (you can
still use PHP as CLI or with Lynx).


If you look through the archives this was discussed a month or so back
in great detail. One thread was "PHP / Bulk Email" on 4th Sept, another
"bulk mail()" and "sending 1000 emails to subscri.." both 12th June.


CC 필드를 사용하고, 5000 email은 보내지 마라.
그런데 id와 가입일 등을 본문에 넣어야 하는데 ?

Maximum execution PHP sendmail

----------------------------------------------------------
/var/log/maillog 리스타트 로그

Dec 17 00:54:24 localhost sendmail[1010]: alias database /etc/aliases rebuilt by root
Dec 17 00:54:24 localhost sendmail[1010]: /etc/aliases: 63 aliases, longest 10 bytes, 625 bytes total
Dec 17 00:54:25 localhost sendmail[1034]: starting daemon (8.12.8): SMTP+queueing@01:00:00
Dec 17 00:54:26 localhost sm-msp-queue[1043]: starting daemon (8.12.8): queueing@01:00:00

----------------------------------------------------------
delay=08:47:08 음. 8시간이 넘어갈때가 있군...--;
이 부분을 20초 정도넘으면 바로 차단 할 수 없나.
delay 땜시 mail() 에서 실행시간 초과 메시지가 떳군.

delay long

DNS문제 거나, 상대편 DNS를 찾지 못하거나..또는 내 DNS 설정이 잘못 됏거나
Timeout.ident 를 줄여라 5s 정도로



sendmail.cf 에서
Timeout.connect
다른 메일서버로의 접속 타임아웃을 의미합니다. 'Timeout.command'와 반대의 개념을 생각하시면 됩니다.

* Timeout.helo
다름 메일서버의 ESMTP에게 신분을 밝히는(?) 역할의 시간을 의미하는데 예를 들어 'abc.com'이라는 메일서버라
면 'abc.com'이 메일을 받을 수 있다는 응답의 시간이라고 보면 됩니다

* Timeout.command
Sendmail이 다른 메일서버로부터 메일을 받을 때 적용이 되는 시간으로 다른 메일서버로부터 메일을 받을지에 관
련한 명령을 기다리는 설정입니다. 메일을 받는지 아닌지에 관련한 설정이며 일반적으로 활성화시키지는 않습니
다. 최소는 5분입니다.

* Timeout.queuereturn=5d
메일을 보내려는 호스트에 문제가 생겼을 경우 Sendmail이 메일을 보내려고 계속적으로 시도하는 시간을 말합니
다. 이 시간이 지나면 메일을 보낸사람에게 되돌려 보냅니다. 기본적으로 5일로 설정이 되어있습니다.

* Timeout.queuewarn
메일서버가 받은 메시지가 제대로 전달이 되지 않았을 경우 Sendmail이 해당 메일이 제대로 도착할 때까지 시도
하는 시간을 의미합니다. 기본은 4시간으로 설정이 되어있으며 일반적으로 메일서버에 해당 유저가 없을 경우 보
낸 사람에게 발송됩니다
★★ sendmail.cf 설정
O Timeout.connect=10s
O Timeout.iconnect=2s
O Timeout.helo=2m
O Timeout.rcpt=2m
O Timeout.mail=2m
O Timeout.command=2m
O Timeout.ident=5s
O Timeout.queuereturn=2m
O Timeout.queuewarn=3m
O Timeout.hoststatus=30m

음 위처럼 설정해도 1시간 짜리 delay가 있군.
to=<leejoochul@netian.com>, delay=01:00:00

1시간 짜리 밖에 없고, 5-6시간 짜리는 없군. ★
O Timeout.rcpt=5m 으로 줄여보자

@nexonclub.com, @netian.com 이 주로 delay가 5분 넘게 걸리는 군 --;
5분 이상은 없어짐 !

O Timeout.helo=2m
O Timeout.rcpt=2m
O Timeout.mail=2m
O Timeout.command=2m
O Timeout.queuereturn=2m

★모두 2분이하로 !! --> 대용량 발송일 경우에만 설정 임 !!

fsockopen() 에서 HELO , RCPT 등 소켓


----------------------------------------------------------
php.ini 설정 ★★

max_execution_time = 600     ; Maximum execution time of each script, in seconds
memory_limit = 32M      ; Maximum amount of memory a script may consume (8MB)

php.ini 실행시간하고 sendmail.cf 파일 Timeout.* 옵션 변경 하고 조금 양호해 진듯 (?)

팬2 MMX 128ram에서 하루 최고는 6-7만개 정도 나갑니다. -> 1분에 4-50개 정도 밖에 안가네요. 내용도 많고, 부
적격 메일 주소도 많고..
팬4 1G,1G ram일 경우는 하루에 20만개 정도도 가능하구요.
물론 네트웍이 받쳐주면 더 될 수도

테스트 할 적에 우선 내 메일주소로 5천개 정도를 보내 보세요.
그 5천개를 보낸 시간* 2배 정도 가 실제 메일을 보내는 시간이 됩니다.
(5천개를 보내는데 1시간 걸렸다면, 실제 보내는 시간은 2시간 정도 되구요.
5천개 중에, 1천개는 메일큐에서 삭제되고, 1천개는 발송되므로, 실제 발송량은 3천개 정도 밖에 안됩니다. )

부적격 메일 주소가 많기 때문인 것이 가장 큰 원인이죠.

회원가입 시에 ID를 메일주소로 설정하고, 가입 시에 메일주소로 비번을 쏘는 방식이라면,
메일링이 훨씬 쉬워 질 검다.
=================================================
Sendmail RPM 설치 및 설정

http://www.funix.org/fr/linux/sendmail.htm
http://www.funix.org/fr/linux/sendmail2.htm
=================================================

메모리가 거의 바닥이면 중지한다. --;

숨은참조나 참조로 보내면 좋은데, 내용에 ID와 가입일짜가 들어가기 땜시...흠...

=================================================
용량이 어느정도 되면, /var/log/maillog 파일을 다른곳으로 이동 !

메일 로그 파일을 지워도 메모리 해제 NO
받은메일을 지워도 메모리 해제 NO

memory revoke ?

서버를 재부팅하고, 바로 메일을 쏘면 24개 정도의 sendmail 자식 프로세스가 생긴다.
그러다가 5천개 정도 보내면 3-4개 정도로 줄어 버린다.

메모리의 영향인가 ? CPU의 영향인가?

=================================================
팬2 MMX - 128ram - Sendmail ★

2시 20분 시작 ! 6만2천개 파일 - PHP 파일 5메가. 메모리 점유율 14-16메가
워낙 시스템이 꼬져서 파일 2개 정도로 나누는 것이 좋을듯. 8만,6만 으로

# uptime  
18:51:23  up  4:37,  2 users,  load average: 0.95, 1.53, 1.56


85메가 여유 공간
# free -m
             total       used       free     shared    buffers     cached
Mem:           123        116          7          0         33         44
-/+ buffers/cache:         37         85
Swap:          129          1        128

# ps -aux|grep sendmail
평균 10개 sendmail 자식 프로세스( 적을때 5개, 많을 경우 24개 )

# ps -aux|grep php

# ps -aux|grep sendmail 해서 20분 이상된 프로세스는 kill -9로 죽여라.
메모리를 많이 차지 하기 때문에 죽이면 , 다른 여러개의 sendmail 프로세스가 생성되서 좋다.
Sendmail 기본 데몬은 죽이지 마라! smmsp, pts/1

# mailq

2만개 가다가 죽음 . 5시간 정도.
<b>Fatal error</b>:  Maximum execution time of 180 seconds exceeded in
<b>/home/mailing/homepage/mailing/mail_sender3.php</b> on line <b>19</b><br />
=================================================


@nexonclub.com, @netian.com 이 주로 delay가 5분 넘게 걸리는 군 --;


=================================================
수신확인 -> html 이미지 파일에 DB 링크 나 image 파일 을 특정 도메인으로 분리

발송 성공 -> maillog 에서 stat=Sent
/var/log/maillog

발송 실패 -> maillog 에서 stat=Deferred

반송 -> pop3나 imap /var/spool/mail/ 아래 사용자 계정 파일로 들어 온다.
djdjdjfueueueu@empal.com 으로 잘못된 메일을 보내면 Sendmail maillog에는 Sent로 나오고, 다음과 같은 메시지

반송 된다.  Returned mail: see transcript for details


=================================================

PHP에서 메시지 내용을 include_once 문으로 사용하지 말것 ! include 문 사용해라 !
처음 것만 읽고, 나중 것은 모두 처음 것과 동일 .

include_once "message.php";


/var/log/maillog 파일에서 다음과 같은 것이 있다. 한글 이름을 읽지 못해서 다음과 같이 표시 된다. 같은 이름
으로 가는 것은 아니다.
to=\377\377\377\377\377\377

=================================================

mx 레코드 체크
mx 레코드는 도메인 이름의 편지를 처리하거나 전달할 때 반드시 필요하다.
메일링 리스트에서 메일주소 목록을 만들 경우 mx 체크를 하는 것이 좋다.

http://www.tood.net/tood/toodboard/toodread.php?board=tootech&tcode=2062

<?php
function checkEmail($Email) {
   //정규식 매칭
   if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $Email)) {
       return FALSE;
   }

   //도메인과 사용자 분리
   list($Username, $Domain) = split("@",$Email);

   //MX  레코드 체크 - 윈도우서 사용불 가
   if(getmxrr($Domain, $MXHost)) {
       return TRUE;
   }
   else {
       //소켓 25번 연결
       if(fsockopen($Domain, 25, $errno, $errstr, 30)) {
           return TRUE;
       }
       else {
           return FALSE;
       }
   }
}
//$Email="sss@kkk.com";
$Email="sss@90832.com";

$a=checkEmail($Email);
print $a;// 1이면 가능 , 값이 없으면 불가

?>

'프로그래밍 > PHP' 카테고리의 다른 글

php로 메일받아 파싱 하기  (0) 2008.06.22
php - SMTP Mail Class  (0) 2008.06.22
php 템플릿 powered by Smarty  (0) 2008.06.22
php 좀 더 나은 퍼포먼스를 위하여  (0) 2008.06.22
php 기본참고사항  (0) 2008.06.22
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크