从LightSwitch应用程序发送电子邮件

时间:2022-11-15 10:39:43

Updated for bounty. What I am after is a simple way to send e-mail when I click a button on one of my LightSwitch Screens. I need to be able to access data from any screen (to collect and process it) so it can be sent as an e-mail. How can this be done without breaking my back over it, or using any third party components or services? Third party stuff isn't an option in this case.

更新的赏金。当我点击我的一个LightSwitch屏幕上的一个按钮时,我想要的是一个简单的发送电子邮件的方法。我需要能够从任何屏幕访问数据(以便收集和处理数据),以便可以以电子邮件的形式发送数据。如何在不破坏我的支持的情况下完成这项工作,或者使用任何第三方组件或服务?在这种情况下,第三方的东西不是一个选项。


I have followed every tutorial I could find, and it just doesn't work. I cannot send an email to someone from a LightSwitch application, no matter how I do it. I can send email from WinForms, WPF, Websites - so I know it's not my code that's the problem.

I have followed this tutorial to a "T", and (http://blogs.msdn.com/b/bethmassi/archive/2011/01/27/how-to-send-html-email-from-a-lightswitch-application.aspx) it still won't work. First, here are my current issues:

我已经按照本教程学习了“T”,并且(http://blogs.msdn.com/b/bethmassi/archive/2011/01/27/how- html-email-from- lightswitch-application.aspx)它仍然不能工作。首先,以下是我目前的问题:

  1. In this tutorial, it tells you to add your Class.cs file to the UserCode folder in the Server folder - I did that.
  2. 在本教程中,它告诉您添加类。cs文件到服务器文件夹中的UserCode文件夹——我做到了。
  3. It also tells you to Add a reference to System.Net.Mail (obviously) - I tried that. System.Net.Mail is not available to be added. I can't find it anywhere!
  4. 它还告诉您添加对System.Net的引用。邮件(显然)——我试过了。System.Net。无法添加邮件。我在任何地方都找不到它!
  5. Every other tutorial is the same - so there's nothing else that I can try, that I know of.
  6. 其他的教程都是一样的,所以我没有别的可以尝试的,我知道的。

As you can see below, I try adding System.Net.Mail as a reference, but it's not there in the list. I've also tried adding the using System.Net.Mail to the top of the files, but like I said; it's not available/does not exist/whatever.

如下所示,我尝试添加System.Net。邮件作为参考,但不在列表中。我还尝试添加了using System.Net。邮件到文件的顶部,但正如我说的;它不存在/不存在/无所谓。

从LightSwitch应用程序发送电子邮件

Anyone know how to send email from a LightSwitch application?

有人知道如何从LightSwitch应用程序发送电子邮件吗?

Note, this is not a service, or website type project, just a simple Desktop Lightswitch app.

注意,这不是一个服务或网站类型项目,只是一个简单的桌面Lightswitch应用。

I have an invoice management app that I'm making, and the only part left is to auto-send a payment due reminder email if the payment is way overdue, based on the DateDue value in the table.

我有一个正在开发的发票管理应用,唯一剩下的部分是根据表格中的日期到期价值自动发送一个付款到期提醒邮件。

I've seen other comments on MSDN forums by people who said that System.Net.Mail is not available in Silverlight, and that's why it's not there in LightSwitch. I don't know if that's true or not, but it certainly is looking that way. Why couldn't they have just made System.Net.Mail available for LightSwitch apps without making us jump through hoops just to get it working?

我在MSDN论坛上看到过有人说过System.Net。邮件在Silverlight中不可用,这就是为什么它不在LightSwitch中。我不知道这是真的还是假的,但确实是这样的。为什么他们不能创建system。net。为LightSwitch应用程序提供的邮件不会让我们为了让它正常工作而跳来跳去?

Even though I said I know my code is fine, I'll post it anyway.

即使我说我知道我的代码没问题,我还是要把它贴出来。

C#: (Note that in my CLASS file System.Net.Mail IS available HOWEVER, I am not able to access any part of this code in this file from anywhere else or any other file in my entire project!)

注意在我的类文件System.Net中。邮件是可用的,但是,我不能从任何地方或我整个项目中的任何其他文件访问这个文件中的任何部分!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;

namespace LightSwitchApplication
{
    public class JTS
    {
        public class Mail
        {
            public string recipient { get; set; }
            public string subject { get; set; }
            public string message { get; set; }

            public void Send()
            {
                using (MailMessage mailmessage = new MailMessage())
                {
                    mailmessage.From = new MailAddress("@.com");
                    mailmessage.To.Add(recipient);
                    mailmessage.Subject = subject;
                    mailmessage.Body = message;
                    mailmessage.Priority = MailPriority.High;

                    using (SmtpClient client = new SmtpClient())
                    {
                        client.Credentials = new System.Net.NetworkCredential("@.com", "_SVN");
                        client.EnableSsl = false;
                        client.Host = "m..com";
                        client.Port = 25;
                        client.Send(mailmessage);
                    }
                }
            }
        }
    }
}

2 个解决方案

#1


2  

System.Net.Mail is a namespace, not an assembly. Try adding a reference to System.Net to see if that helps.

System.Net。邮件是一个名称空间,而不是一个程序集。尝试向系统添加一个引用。看看这是否有帮助。

That tutorial you mentioned references this one, where it is System.Net they are adding the reference to.

你提到的那个教程提到了这个系统。他们将引用添加到。

#2


1  

You should be able to add a reference to System.Net to the Server project, as that project is a .NET project, that has no restrictions on what code you can use, unlike Silverlight projects. So, you would right-click the Server project, & select "Add Reference", then locate the System.Net assembly.

您应该能够向系统添加引用。Net到服务器项目,因为这个项目是。Net项目,不像Silverlight项目,它不限制你可以使用什么代码。因此,您将右键单击服务器项目,并选择“添加引用”,然后定位系统。净组装。

The methods in the articles DO work, but what may not be so apparent is that although you can work with .NET code in the Server project, you can't directly access that code (or your own code) from the Client project.

本文中的方法确实有效,但可能不太明显的是,尽管您可以在服务器项目中使用. net代码,但您不能直接从客户端项目访问该代码(或您自己的代码)。

Have a look at this article about what we call the "Command Table Pattern" that's used to get around the fact that client project code can't directly call server project code.

请阅读本文,了解我们所称的“命令表模式”,该模式用于避免客户端项目代码不能直接调用服务器项目代码这一事实。

Another alternative, is to use the Office Integration Pack extension that's available for free that "makes it easy to manipulate the 2010 versions of Excel, Word and Outlook in a variety of ways common in desktop business applications. Create documents, PDFs, spreadsheets, email and appointments using data from your LightSwitch applications".

另一种选择是使用Office Integration Pack扩展,该扩展可以免费使用,“使您能够轻松地以桌面业务应用程序中常见的各种方式操作Excel、Word和Outlook的2010版本。”使用来自LightSwitch应用程序的数据创建文档、pdf文件、电子表格、电子邮件和约会”。

And there's a sample application available for download as well.

还有一个示例应用程序可供下载。

I hope this helps.

我希望这可以帮助。

#1


2  

System.Net.Mail is a namespace, not an assembly. Try adding a reference to System.Net to see if that helps.

System.Net。邮件是一个名称空间,而不是一个程序集。尝试向系统添加一个引用。看看这是否有帮助。

That tutorial you mentioned references this one, where it is System.Net they are adding the reference to.

你提到的那个教程提到了这个系统。他们将引用添加到。

#2


1  

You should be able to add a reference to System.Net to the Server project, as that project is a .NET project, that has no restrictions on what code you can use, unlike Silverlight projects. So, you would right-click the Server project, & select "Add Reference", then locate the System.Net assembly.

您应该能够向系统添加引用。Net到服务器项目,因为这个项目是。Net项目,不像Silverlight项目,它不限制你可以使用什么代码。因此,您将右键单击服务器项目,并选择“添加引用”,然后定位系统。净组装。

The methods in the articles DO work, but what may not be so apparent is that although you can work with .NET code in the Server project, you can't directly access that code (or your own code) from the Client project.

本文中的方法确实有效,但可能不太明显的是,尽管您可以在服务器项目中使用. net代码,但您不能直接从客户端项目访问该代码(或您自己的代码)。

Have a look at this article about what we call the "Command Table Pattern" that's used to get around the fact that client project code can't directly call server project code.

请阅读本文,了解我们所称的“命令表模式”,该模式用于避免客户端项目代码不能直接调用服务器项目代码这一事实。

Another alternative, is to use the Office Integration Pack extension that's available for free that "makes it easy to manipulate the 2010 versions of Excel, Word and Outlook in a variety of ways common in desktop business applications. Create documents, PDFs, spreadsheets, email and appointments using data from your LightSwitch applications".

另一种选择是使用Office Integration Pack扩展,该扩展可以免费使用,“使您能够轻松地以桌面业务应用程序中常见的各种方式操作Excel、Word和Outlook的2010版本。”使用来自LightSwitch应用程序的数据创建文档、pdf文件、电子表格、电子邮件和约会”。

And there's a sample application available for download as well.

还有一个示例应用程序可供下载。

I hope this helps.

我希望这可以帮助。