繁体   English   中英

c#使用Process.Start发送电子邮件

[英]c# Send Email using Process.Start

我想使用默认电子邮件应用程序发送不带附件的简单电子邮件。

我知道可以使用Process.Start来完成,但是我无法使其正常工作。 这是我到目前为止的内容:

string mailto = string.Format("mailto:{0}?Subject={1}&Body={2}", "to@user.com", "Subject of message", "This is a body of a message");
System.Diagnostics.Process.Start(mailto);

但是它只是打开带有预写文本的Outlook消息。 我想直接发送此邮件,而无需用户手动单击“发送”按钮。 我想念什么?

谢谢

您需要这样做:

string mailto = string.Format("mailto:{0}?Subject={1}&Body={2}", "to@user.com", "Subject of message", "This is a body of a message");
mailto = Uri.EscapeUriString(mailto);
System.Diagnostics.Process.Start(mailto);

我不确定Process.Start()它可能始终只会在默认的Mail-App中打开邮件,而不会自动发送。

但是可能有两种选择:

您需要这样做:

            SmtpClient m_objSmtpServer = new SmtpClient();
            MailMessage objMail = new MailMessage();
            m_objSmtpServer.Host = "YOURHOSTNAME";
            m_objSmtpServer.Port = YOUR PORT NOS;

            objMail.From = new MailAddress(fromaddress);
            objMail.To.Add("TOADDRESS");

            objMail.Subject = subject;
            objMail.Body = description;
            m_objSmtpServer.Send(objMail);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM