Я использую API Gmail и пытаюсь отправить электронное письмо с вложением в формате PDF. Вложение в формате PDF включает в себя промо-письма из моего почтового ящика. Все работает нормально, пока я не попытаюсь отправить сообщение с приложением. Я получаю эту ошибку, сообщая, что программное обеспечение на моем хост-компьютере прервало соединение.
System.Net.Http.HttpRequestException
HResult=0x80131500
Message=Error while copying content to a stream.
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Requests.ClientServiceRequest`1.<ExecuteUnparsedAsync>d__30.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Google.Apis.Requests.ClientServiceRequest`1.Execute()
at Newspaper.Newspaper.SendEmail(GmailService gmailservice, MimeMessage msg, String id) in F:\Learning\CSharp\Projects\EasyMail\Program.cs:line 233
at Newspaper.Newspaper.Main(String[] args) in F:\Learning\CSharp\Projects\EasyMail\Program.cs:line 68
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.
Inner Exception 2:
SocketException: An established connection was aborted by the software in your host machine
Вот фрагмент кода:
static void Main(string[] args)
{
UserCredential credential;
using (var stream =
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"admin",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
CreateFile();
var msgList = GetMessageList(service);
// gets content of all messages and puts it into a HTML file
GetAllMessages(msgList);
ToPDF(newsfname);
SendEmail(service, CreateEmail(credential.UserId), credential.UserId);
}
// connection aborts here
static void SendEmail(GmailService gmailservice, MimeMessage msg, string id) {
Message message = new Message();
message.Raw = Encode(msg.ToString());
gmailservice.Users.Messages.Send(message, id).Execute();
}
Что вызывает его прервана? и как ок