使用TinyMail的API函数发送邮件

 一个发送邮件的简单模型代码:
int myrecieve(void)
{
        CamelURL *url;

        g_type_init();
        if (!g_thread_supported ())
            g_thread_init(NULL);
        camel_init(NULL, 0);

        camel_provider_init();
        CamelException* ex = camel_exception_new();

        CamelSession* session = CAMEL_SESSION(camel_object_new(CAMEL_SESSION_TYPE));
        camel_session_construct(session, "/tmp");
        url = camel_url_new("http://www.sina.com", ex);
        printf("url = %p/n", url);
        if (url) {
            camel_url_set_protocol(url, "pop");
            camel_url_set_user (url, "abc");
            camel_url_set_passwd (url, "12345678");
            camel_url_set_host (url, "pop3.sina.com");
            camel_url_set_port (url, 110);
            camel_url_set_authmech(url, NULL);
        }
        printf("url = %s/n", camel_url_to_string(url, 10));
        CamelStore *store = CAMEL_STORE(camel_session_get_service_connected(session,
                          url,
                        CAMEL_PROVIDER_STORE,
                        ex));
        camel_url_free(url);
       
         printf("Harrison: %p/n", store);
        CamelFolder* inbox = camel_store_get_inbox(store, ex);
        GPtrArray* uids = camel_folder_get_uids(inbox);

        int i = 0;
        for(i = 0; i < uids->len; i++)
        {
                CamelMimeMessage* message = camel_folder_get_message(inbox, uids->pdata[i],
                                                                                                 ex);
                camel_mime_message_dump(message, 1);
                CamelStream* fs = camel_stream_fs_new_with_name(uids->pdata[i], O_CREAT|O_RDWR, 0664);
                camel_data_wrapper_write_to_stream(CAMEL_DATA_WRAPPER(message), fs);

                camel_object_unref(CAMEL_OBJECT(fs));
                camel_object_unref(CAMEL_OBJECT(message));
        }
        camel_folder_free_uids(inbox, uids);

        camel_object_unref(CAMEL_OBJECT(store));
        camel_object_unref(CAMEL_OBJECT(session));
        camel_exception_free(ex);

        return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值