如何从Windows Mobile 5.0发送电子邮件

时间:2012-09-28 06:10:04

标签: c# .net email windows-mobile windows-phone

我正在尝试在visual studio 2008中为Windows手机创建一个简单的电子邮件发送应用程序,所以请告诉我必须使用哪些类或方法。

我试过这个,但它不起作用:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Configuration;
using System.Xml;


      try
        {
            Application.DoEvents();
            // setup mail message
            MailMessage message = new MailMessage();
            message.From = new MailAddress(textBox1.Text);
            message.To.Add(new MailAddress(textBox2.Text));
            message.Subject = textBox3.Text;
            message.Body = textBox5.Text;

            // setup mail client
            SmtpClient mailClient = new SmtpClient("smtp.gmail.com");
            mailClient.Credentials = new NetworkCredential(textBox1.Text, textBox4.Text);
            mailClient.Send(message);

            MessageBox.Show("Sent");

        }
        catch (Exception)
        {
            MessageBox.Show("Error");
        }

我收到了这些错误:

Error   1   The type or namespace name 'MailMessage' could not be found (are you missing a using directive or an assembly reference?)
Error   2   The type or namespace name 'MailMessage' could not be found (are you missing a using directive or an assembly reference?)
Error   3   The type or namespace name 'MailAddress' could not be found (are you missing a using directive or an assembly reference?)
Error   4   The type or namespace name 'MailAddress' could not be found (are you missing a using directive or an assembly reference?)
Error   5   The type or namespace name 'SmtpClient' could not be found (are you missing a using directive or an assembly reference?)
Error   6   The type or namespace name 'SmtpClient' could not be found (are you missing a using directive or an assembly reference?)
Error   7   The type or namespace name 'SmtpClient' could not be found (are you missing a using directive or an assembly reference?)
Error   8   The type or namespace name 'SmtpClient' could not be found (are you missing a using directive or an assembly reference?)

2 个答案:

答案 0 :(得分:1)

.NET Compact框架不支持System.Net.Mail或System.Web.Mail。您可以使用http://www.opennetcf.com/library/sdf/html/7e16eccb-dc9e-4559-c79c-cfaad631ac15.htm等扩展名,或者呼叫代表您发送电子邮件的服务。

答案 1 :(得分:0)

要在Windows Mobile上发送邮件等,您必须启动VisualStudio C#/ VB SmartDevice项目。

可以通过命名空间microsoft.windowsmobile.pocketoutlook访问邮件等。您必须添加对包含WindowsMo​​bile程序集的Windows Mobile 5(或更高版本)SDK目录的引用。

http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.pocketoutlook.aspx

这是一个简单的片段,没有首先打开一个poom帐户等所需的东西:

http://cjcraft.com/blog/2008/10/02/how-to-open-a-mail-in-inbox-using-pocket-outlook/