soapadapter.asmx

来自「用C#开发实现SMTP相关技术,能接收到带附件的邮件服务功能.」· ASMX 代码 · 共 45 行

ASMX
45
字号
<%@ WebService Language="C#" Class="SoapAdapter" %>

using System;
using System.Reflection;
using System.Web.Services;
using OpenSmtp.Mail;


[ WebService (Namespace="http://sourceforge.net/openSmtp") ]
public class SoapAdapter : WebService {

	private Smtp smtp;
	private MailMessage msg;
	private EmailAddress sender;
	private EmailAddress recipient;
	
	[WebMethod]   
	public String Send(string senderEmail, string recipientEmail, 
				string subject, string body, string host, int port) 
	{
		try
		{
			EmailAddress senderAddress = new EmailAddress(senderEmail);
			EmailAddress recipientAddress = new EmailAddress(recipientEmail);
			
			msg 		= new MailMessage(senderAddress, recipientAddress);
			msg.ReplyTo = senderAddress;
			msg.Subject = subject;
			msg.Body 	= body;
			
			Smtp smtp 	= new Smtp(host, port);
			smtp.SendMail(msg);			
		
			return "Message delivered.";
		}
		catch(SmtpException se)
		{
			return "error: " + se.Message;
		}
	}


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?