[研究][ASP.NET 使用 System.Net.Mail.MailMessage 元件 + MDaemon 22.0.3 郵件伺服器寄非加簽信
2022-12-19
[研究]Alt-N MDaemon Email Server 22.0.3郵件伺服器 30 天試用版安裝 (Windows Server 2022)
http://shaurong.blogspot.com/2022/12/alt-n-mdaemon-email-server-2203-30.html
架設完成後,請允許 relay (預設不允許)
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#
********************************************************************************
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button_SendMail" runat="server" Text="Send" OnClick="Button_SendMail_Click" />
<br />
<asp:Label ID="Label_MSG1" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
|
下面信件主旨、內容、寄信者、收信者、IP、寄信長號、密碼請依據實際情況修改。
Default.aspx.cs
using System;
//----------------------------------------
//1.先在專案中加入組件參考:System.Security
//2.設定 using 以下兩個命名空間 System.Security 和 System.Net.Mail.MailMessage
//using MailMessage = System.Web.Mail.MailMessage; ///過時
using MailMessage = System.Net.Mail.MailMessage;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_SendMail_Click(object sender, EventArgs e)
{
//https://learn.microsoft.com/zh-tw/dotnet/api/system.net.mail.mailmessage?view=netframework-4.8
// public MailMessage (string from, string to, string subject, string body);
MailMessage message = new MailMessage(
"jane@contoso.com",
"user1@contoso.com", |
Relay 沒有允許 (預設)
From 的 Email 若是 MDaemon 上的,會出現錯誤。
SMTP 伺服器需要安全連接,或用戶端未經驗證。 伺服器回應為: 5.7.0 Authentication required
From 的 Email 若非 MDaemon 上的,會出現錯誤。
無法使用信箱。 伺服器回應為: 5.1.1 Recipient unknown
Relay 允許後
實際測試,client.EnableSsl = false; 也可以。實際測試,
client.UseDefaultCredentials = false;
client.EnableSsl = true;
也可以。
實際測試,
client.UseDefaultCredentials = false;
client.EnableSsl = false;
也可以。
(完)
相關

沒有留言:
張貼留言