如何将附件添加到使用API方法发送电子邮件的电子邮件
How to add attachment to a Email that uses API method to send Email
我正在创建一个如下所示的 Even 附件。
string schLocation = "Conference Room";
string schSubject = "Business visit discussion";
string schDescription = "Schedule description";
System.DateTime schBeginDate = Convert.ToDateTime("7/3/2008 10:00:00 PM");
System.DateTime schEndDate = Convert.ToDateTime("7/3/2008 11:00:00 PM");
//PUTTING THE MEETING DETAILS INTO AN ARRAY OF STRING
String[] contents = { "BEGIN:VCALENDAR",
"PRODID:-//Flo Inc.//FloSoft//EN",
"BEGIN:VEVENT",
"DTSTART:" + schBeginDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z"),
"DTEND:" + schEndDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z"),
"LOCATION:" + schLocation,
"DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + schDescription,
"SUMMARY:" + schSubject, "PRIORITY:3",
"END:VEVENT", "END:VCALENDAR" };
/*THE METHOD 'WriteAllLines' CREATES A FILE IN THE SPECIFIED PATH WITH
THE SPECIFIED NAME,WRITES THE ARRAY OF CONTENTS INTO THE FILE AND CLOSES THE
FILE.SUPPOSE THE FILE ALREADY EXISTS IN THE SPECIFIED LOCATION,THE CONTENTS
IN THE FILE ARE OVERWRITTEN*/
System.IO.File.WriteAllLines(Server.MapPath("Sample.ics"), contents);
//METHOD TO SEND EMAIL IS CALLED
// SendMail();
//System.Net.Mail.Attachment mailAttachment = new Attachment(Server.MapPath("Sample.ics"));
}
现在我想通过电子邮件发送附件,而不是使用 smtp,而是使用 API 方法,例如 HttpBasicAuthenticator
我如何在 smtp 中使用此方法发送附件,它是一个库 Attachment
什么是用于 API ?
我找到了答案
通过 API 发送电子邮件时,您使用
RestClient client = new RestClient();
然后用这行代码有一个附件
request.AddFile("attachment", path);
看起来像这样
来源LinkDocumentation
我正在创建一个如下所示的 Even 附件。
string schLocation = "Conference Room";
string schSubject = "Business visit discussion";
string schDescription = "Schedule description";
System.DateTime schBeginDate = Convert.ToDateTime("7/3/2008 10:00:00 PM");
System.DateTime schEndDate = Convert.ToDateTime("7/3/2008 11:00:00 PM");
//PUTTING THE MEETING DETAILS INTO AN ARRAY OF STRING
String[] contents = { "BEGIN:VCALENDAR",
"PRODID:-//Flo Inc.//FloSoft//EN",
"BEGIN:VEVENT",
"DTSTART:" + schBeginDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z"),
"DTEND:" + schEndDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z"),
"LOCATION:" + schLocation,
"DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + schDescription,
"SUMMARY:" + schSubject, "PRIORITY:3",
"END:VEVENT", "END:VCALENDAR" };
/*THE METHOD 'WriteAllLines' CREATES A FILE IN THE SPECIFIED PATH WITH
THE SPECIFIED NAME,WRITES THE ARRAY OF CONTENTS INTO THE FILE AND CLOSES THE
FILE.SUPPOSE THE FILE ALREADY EXISTS IN THE SPECIFIED LOCATION,THE CONTENTS
IN THE FILE ARE OVERWRITTEN*/
System.IO.File.WriteAllLines(Server.MapPath("Sample.ics"), contents);
//METHOD TO SEND EMAIL IS CALLED
// SendMail();
//System.Net.Mail.Attachment mailAttachment = new Attachment(Server.MapPath("Sample.ics"));
}
现在我想通过电子邮件发送附件,而不是使用 smtp,而是使用 API 方法,例如 HttpBasicAuthenticator
我如何在 smtp 中使用此方法发送附件,它是一个库 Attachment
什么是用于 API ?
我找到了答案 通过 API 发送电子邮件时,您使用
RestClient client = new RestClient();
然后用这行代码有一个附件
request.AddFile("attachment", path);
看起来像这样
来源LinkDocumentation