zoukankan      html  css  js  c++  java
  • MIME::Lite模拟邮件发送

    用法:

    默认发送单一附件的邮件:

        use MIME::Lite;
        ### Create a new single-part message, to send a GIF file:
        $msg = MIME::Lite->new(
            From     => 'me@myhost.com',
            To       => 'you@yourhost.com',
            Cc       => 'some@other.com, some@more.com',
            Subject  => 'Helloooooo, nurse!',
            Type     => 'image/gif',
            Encoding => 'base64',
            Path     => 'hellonurse.gif'
        );
        $msg->send; # send via default

    创建多个附件的邮件

        ### Create a new multipart message:
        $msg = MIME::Lite->new(
            From    => 'me@myhost.com',
            To      => 'you@yourhost.com',
            Cc      => 'some@other.com, some@more.com',
            Subject => 'A message with 2 parts...',
            Type    => 'multipart/mixed'
        );
    
        ### Add parts (each "attach" has same arguments as "new"):
        $msg->attach(
            Type     => 'TEXT',
            Data     => "Here's the GIF file you wanted"
        );
        $msg->attach(
            Type     => 'image/gif',
            Path     => 'aaa000123.gif',
            Filename => 'logo.gif',
            Disposition => 'attachment'
        );
        ### use Net:SMTP to do the sending
        $msg->send('smtp','some.host', Debug=>1 );

    创建一个只有文本的邮件:

    $msg = MIME::Lite->new(
            From     =>'me@myhost.com',
            To       =>'you@yourhost.com',
            Cc       =>'some@other.com, some@more.com',
            Subject  =>'Helloooooo, nurse!',
            Data     =>"How's it goin', eh?"
        );

    注意:认证方式发送,系统需安装MIME::Base64 and Authen::SASL

    MIME::Lite     模块的参数类型决定附件的类型和附件的添加方法:
    Path     指定作为附件的文件的路径
    Filename     指定接受方保存附件时,附件的默认文件名.如果指定了 Path 参数,那么默认的文件名就是路径中的名字
    Date    指定附件添加的日期
    Type     指定待添加附件的文件编码类型
    Disposition    它的值只能是 inline 和 attachment.前者指定接受方打开邮件的时候附件内容会跟在邮件正文后显示,而不单独作为一个附加物.后者指定接受方应该指定一个附件的解码方 法,并且保存附件,此时会有提示

    MIME::Lite 附录:

    MIME::Lite 参数采用“参数名=>值”对形式.

    MIME::Lite 头

    Approved Encrypted Received Sender
    Bcc From References Subject
    Cc Keywords Reply-To To
    Comments Message-ID Resent- X-
    Content-* MIME-Version Return-Path
    Date Organization

    MIME::Lite 参数类型

    Data FH ReadNow
    Datestamp Filename Top
    Disposition Id Type
    Encoding Length
    Filename Path

    常用附件编码类型
    TEXT      代表 text/plain,为 Type 的默认值;
    BINARY     是 application/octet-stream 的缩写;
    multipart/mixed     表明邮件有附件;
    application/msword     表明附件为微软的 Word 文档;
    application/vnd.ms-excel      表明附件为微软的 Excel 文档;
    application/pdf     表明附件为 PDF 文档;
    image/gif,image/jpeg,image/png      分别指定 GIF,JPEG,PNG 文件;
    audio/mpeg      指定 MP3 格式文件;video/mpeg 指定 MPEG 格式影片;
    video/quicktime     指定Quicktime 格式文件.

  • 相关阅读:
    mybatis关键查询
    智能标签
    mybatis注解基础使用
    myBatis基础知识点
    Mybatis框架模糊查询
    python(7):sympy模块
    anaconda中的包如何传到pycharm中使用?
    python(6):Scipy之pandas
    python(5):scipy之numpy介绍
    python(4): regular expression正则表达式/re库/爬虫基础
  • 原文地址:https://www.cnblogs.com/tjxwg/p/2979297.html
Copyright © 2011-2022 走看看