我正在嘗試爲本地樂隊簡報設置此腳本。Perl - 如何從頭部的FROM部分獲取電子郵件地址?
目前,有人發送一封電子郵件,其中包含要添加的請求,我們將其手動添加到我設置的通訊郵件程序中。 (這工作很好,謝謝我在這裏找到的幫助!)
現在的意圖是讓我的腳本登錄到我爲我們的服務器上的列表設置的電子郵件帳戶,獲取信息以自動添加電子郵件。
我知道有一堆應用程序可以做到這一點,但我想了解自己。
我已經有「添加到列表」時,有一個電子郵件地址從標題下方的返回(從)工作,但是,有時頭(從)是一個名稱,而不是電子郵件地址(eg "persons name" is returned from persons name<[email protected]> but, not the <[email protected]>
。)
現在,我不是沉迷於下面的方法,但是,它着名... ...的一個點。
我閱讀了關於這些模塊的所有文檔,沒有任何我能找到的東西在那裏得到電子郵件。
有人可以幫我嗎?詳細的例子非常感謝,因爲我正在努力學習Perl。
#!/usr/bin/perl -w
##########
use CGI;
use Net::IMAP::Simple;
use Email::Simple;
use IO::Socket::SSL; #optional i think if no ssl is needed
use strict;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
######################################################
# fill in your details here
my $username = '#########';
my $password = '#############';
my $mailhost = '##############';
#######################################################
print CGI::header();
# Connect
my $imap = Net::IMAP::Simple->new($mailhost, port=> 143, use_ssl => 0,) || die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";
# Log in
if (!$imap->login($username, $password)) {
print STDERR "Login failed: " . $imap->errstr . "\n";
exit(64);
}
# Look in the the INBOX
my $nm = $imap->select('INBOX');
# How many messages are there?
my ($unseen, $recent, $num_messages) = $imap->status();
print "unseen: $unseen, <br />recent: $recent, <br />total: $num_messages<br />\n\n";
## Iterate through unseen messages
for (my $i = 1 ; $i <= $nm ; $i++) {
if ($imap->seen($i)) {
my $es = Email::Simple->new(join '', @{ $imap->top($i) });
printf("[%03d] %s\n\t%s\n", $i, $es->header('From'), $es->header('Subject'));
print "<br />";
next;
}## in the long version these are pushed into different arrays for experimenting purposes
else {
my $es = Email::Simple->new(join '', @{ $imap->top($i) });
printf("[%03d] %s\n\t%s\n", $i, $es->header('From'), $es->header('Subject'));
print "<br />";
}
}
# Disconnect
$imap->quit;
exit;
謝謝! my $ line = $ es-> header('From');我的@addresses = Email :: Address-> parse($ line);打印$地址[0] - >地址; – DulcimerDude 2010-11-10 16:54:09
謝謝 - 謝謝 - 謝謝!完善... – DulcimerDude 2010-11-10 17:01:27