如果 A 发送带有小附件的电子邮件,电子邮件 API 会给出响应。但是,如果我发送带有大附件的电子邮件,API 不会等待响应。我尝试过超时,但这没有帮助。我发送的电子邮件的附件最大为 25 MB。
对于大附件,它会立即返回响应,但不会成功。我直接从那个有效的 API 尝试过,但从我的代码来看,它不等待响应。
public static async Task<string> SendEmail1(HttpContextBase contextBase, Email email)
{
string status = string.Empty;
try
{
string Token = await GetVendorToken(contextBase, vendorCredentialDetails);
HttpClient client;
string baseAddress = EHRAppSettingsDictionary.GetKeyValue("abc");
HttpClientHandler handler = new HttpClientHandler();
handler.AutomaticDecompression = DecompressionMethods.GZip;
client = new HttpClient(handler);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.AcceptEncoding.Clear();
client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue(SharedConstants.StringWithQualityHeaderValue));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(SharedConstants.MediaTypeWithQualityHeaderValue));
client.DefaultRequestHeaders.Add("Authorization", Token);
client.BaseAddress = new Uri(baseAddress);
client.Timeout = TimeSpan.FromMinutes(20);
string callingAddress = "api/EMAIL/SendEmail";
HttpResponseMessage VendorDetailsResponse = await client.PostAsJsonAsync(callingAddress, email).ConfigureAwait(false);
if (VendorDetailsResponse.IsSuccessStatusCode)
{
status = "Success";
}
else
{
status = "Error : Integration not enabled.";
}
}
else
{
status = "Error : Integration not enabled.";
}
}
catch (Exception ex)
{
// Handle general exceptions here
status = $"Error: {ex.Message}";
}
return status;
}
asp.net 上的请求大小限制为 30MB,为了克服这个问题,您可以使用以下属性:
[RequestSizeLimit(`int_value`)]
[DisableRequestSizeLimit]