我这里有一堆关于 SMTPClient 发送邮件的代码:
public void SendEmailToCustomer(ReservationDetails reservationDetails, string reason, string cardtype) {
MailMessage msg = new MailMessage(ConfigurationManager.AppSettings["Email.Sender"], reservationDetails.Email);
msg.Subject = this.Subject;
msg.Body = this.Body.Replace("[InvoiceNumber]", reservationDetails.Invoice)
.Replace("[GuestName]", reservationDetails.Name)
.Replace("[GuestTelephone]", reservationDetails.Telephone)
.Replace("[GuestEmail]", reservationDetails.Email)
.Replace("[GuestAddress]", reservationDetails.Address)
.Replace("[GuestCompany]", reservationDetails.CompanyName)
.Replace("[GuestCompanyAddress]", reservationDetails.CompanyAddress)
.Replace("[GuestCompanyNumber]", reservationDetails.CompanyNumber)
.Replace("[OtherRemarks]", reservationDetails.Other)
.Replace("[TransferDescription]", reservationDetails.TransferDescription)
.Replace("[FlightArrivalDate]", reservationDetails.ArrivalDate)
.Replace("[ETA]", reservationDetails.ETA)
.Replace("[FlightArrival]", reservationDetails.FlightArrival)
.Replace("[FlightDepartureDate]", reservationDetails.DepartureDate)
.Replace("[ETD]", reservationDetails.ETD)
.Replace("[FlightDeparture]", reservationDetails.FlightDeparture)
.Replace("[NoOfNights]", reservationDetails.NoOfNights)
.Replace("[CheckIn]", reservationDetails.CheckIn)
.Replace("[CheckOut]", reservationDetails.CheckOut)
.Replace("[RoomName]", reservationDetails.RoomName)
.Replace("[Qty]", reservationDetails.Qty)
.Replace("[RoomAmount]", String.Format("{0:N}", Convert.ToDecimal(reservationDetails.RoomAmount)))
.Replace("[RateRoom]", String.Format("{0:N}", Convert.ToDecimal(reservationDetails.RateRoom)))
.Replace("[NumExtra]", Convert.ToString(reservationDetails.NumExtra))
.Replace("[ExtraAmount]", String.Format("{0:N}", Convert.ToDecimal(reservationDetails.ExtraAmount)))
.Replace("[RateExtra]", String.Format("{0:N}", Convert.ToDecimal(reservationDetails.RateExtra)))
.Replace("[RTTQty]", Convert.ToString(reservationDetails.RTTQty))
.Replace("[RTT]", String.Format("{0:N}", Convert.ToDecimal(reservationDetails.RTT)))
.Replace("[RTTAmount]", String.Format("{0:N}", Convert.ToDecimal(reservationDetails.RTTAmount)))
.Replace("[TotalAmount]", String.Format("{0:N}", Convert.ToDecimal(reservationDetails.TotalAmount)))
.Replace("[ModePay]", reservationDetails.ModePayment)
.Replace("[Reason]", "Reason: " + reason)
.Replace("[CardType]", cardtype)
;
msg.CC.Add(this.AddressCC);
msg.Bcc.Add(this.AddressBCC);
msg.IsBodyHtml = true;
try {
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["Smtp.Client"]);
client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Smtp.Credentials.Username"], ConfigurationManager.AppSettings["Smtp.Credentials.Password"]);
client.Send(msg);
} catch (Exception ex) {
//Do nothing
//throw new Exception("Couldn't send email: <p>" + ex.Message);
} finally {
msg.Dispose();
}
}
发送电子邮件的时间过长(大约 5 秒)。我还处理了 MailMessage。
电子邮件延迟的可能原因是什么。我该如何解决这个问题?
非常感谢!!:D