使用C sharp发送电子邮件
使用C sharp将电子邮件发送到电子邮件地址
C sharp : API文档
使用C sharp发送电子邮件
String afilnet_class="email";
String afilnet_method="sendemail";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_subject="Afilnet - Test email";
String afilnet_to="test@test.com";
String afilnet_email="email+test";
String afilnet_scheduledatetime="";
String afilnet_output="";
// Create an URL request
WebRequest request = WebRequest.Create("https://www.afilnet.com/api/http/?class="+afilnet_class+"&method="+afilnet_method+"&user="+afilnet_user+"&password="+afilnet_password+"&subject="+afilnet_subject+"&to="+afilnet_to+"&email="+afilnet_email+"&scheduledatetime="+afilnet_scheduledatetime+"&output="+afilnet_output);
// Get the response
WebResponse response = request.GetResponse ();
// Get the stream returned by the server
Stream dataStream = response.GetResponseStream();
// Open the stream
StreamReader reader = new StreamReader (dataStream);
// Read the Response
String result = reader.ReadToEnd ();
// Asign vars
var data = new NameValueCollection();
data["class"] = "email";
data["method"] = "sendemail";
data["user"] = "user";
data["password"] = "password";
data["subject"] = "Afilnet - Test email";
data["to"] = "test@test.com";
data["email"] = "email+test";
data["scheduledatetime"] = "";
data["output"] = "";
// Create Web client
var wb = new WebClient();
// Execute POST petition
var response = wb.UploadValues("https://www.afilnet.com/api/http/", "POST", data);
// Get response
string responseString = Encoding.UTF8.GetString(response);
// Asign vars
var data = new NameValueCollection();
data["class"] = "email";
data["method"] = "sendemail";
data["subject"] = "Afilnet - Test email";
data["to"] = "test@test.com";
data["email"] = "email+test";
data["scheduledatetime"] = "";
data["output"] = "";
// Create Web client
var wb = new WebClient { Credentials = new NetworkCredential("user", "password") };
// Execute POST petition
var response = wb.UploadValues("https://www.afilnet.com/api/http/", "POST", data);
// Get response
string responseString = Encoding.UTF8.GetString(response);
String afilnet_class="email";
String afilnet_method="sendemail";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_subject="Afilnet - Test email";
String afilnet_to="test@test.com";
String afilnet_email="email+test";
String afilnet_scheduledatetime="";
String afilnet_output="";
// Allow SSL/TLS config
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// We create the webservice instance (Register Web Service first in project)
var service = new WebService.ApplicationServicesPortTypeClient();
// Call to WebService method
String response = service.call(afilnet_user, afilnet_password, afilnet_class, afilnet_method, "{\"subject\":\""+afilnet_subject+"\",\"to\":\""+afilnet_to+"\",\"email\":\""+afilnet_email+"\",\"scheduledatetime\":\""+afilnet_scheduledatetime+"\",\"output\":\""+afilnet_output+"\"}");
参数 | 描述 | 必修/可选 |
---|---|---|
class=email | 要求的课程:要求的课程 | 必修 |
method=sendemail | 请求的类方法:发出请求的类的方法 | 必修 |
user | 您的Afilnet帐户的用户和电子邮件 | 必修 |
password | 您的Afilnet帐户的密码 | 必修 |
subject | 发件人ID | 必修 |
to | 目标电子邮件 | 必修 |
要发送的电子邮件 | 必修 | |
scheduledatetime | 交货日期和时间,格式为yyyy-mm-dd hh:mm:ss | 可选的 |
output | 结果的输出格式 | 可选的 |
发出请求时,您将收到以下字段:
- status
-
结果(如果status = success),您将在此处收到以下值:
- messageid
- credits
- 错误(如果status = error),在这里您将收到错误代码
下面列出了可能的错误代码
码 | 描述 |
---|---|
MISSING_USER | 不包括用户或电子邮件 |
MISSING_PASSWORD | 不包含密码 |
MISSING_CLASS | 不包括课程 |
MISSING_METHOD | 不包括方法 |
MISSING_COMPULSORY_PARAM | 不包括强制参数 |
INCORRECT_USER_PASSWORD | 用户或密码错误 |
INCORRECT_CLASS | 班级不正确 |
INCORRECT_METHOD | 方法不正确 |
NO_ROUTE_AVAILABLE | 指定的目的地没有可用的路径 |
NO_CREDITS | 您的余额不足 |
参数:
- class : email
- method : sendemail
- user : user
- password : password
- subject : Afilnet - Test email
- to : test@test.com
- email : email+test
- scheduledatetime :
- output :
请求:
https://www.afilnet.com/api/http/?class=email&method=sendemail&user=user&password=password&subject=Afilnet - Test email&to=test@test.com&email=email+test&scheduledatetime=&output=