提问人:Harry Brook 提问时间:8/19/2023 最后编辑:Mark SeemannHarry Brook 更新时间:8/19/2023 访问量:17
SMTP 设置使连接超时
SMTP setup is timing out the connection
问:
我添加了从联系表单中获取响应并将其发送到我提供的电子邮件的功能,然后再次将电子邮件发送给感谢客户,但是当我尝试发送电子邮件时,它花费了太多时间,例如 2 分钟,最后它向我显示连接已超时。作为初学者,这是我添加此类功能的第一个项目,所以请帮助我如何克服这个问题?
using BlueDot_Website.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.Mvc;
namespace BlueDot_Website.Controllers
{
public class ContactController : Controller
{
[HttpPost]
public ActionResult SendEmail(ContactViewModel model)
{
// Send email to business email address
SendBusinessEmail(model);
// Send thank you email to the customer
SendThankYouEmail(model);
// Optionally, you can return a different view to display a confirmation message
return RedirectToAction("Index", "Home");
}
private void SendBusinessEmail(ContactViewModel model)
{
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]"); // Replace with your business email address
message.To.Add("[email protected]"); // Replace with your business email address
message.Subject = "New Contact Form Submission";
message.Body = $"Name: {model.Name}\r\nEmail: {model.Email}\r\nContact Number: {model.ContactNumber}\r\nCompany: {model.Company}\r\nAddress: {model.Address}\r\nCity: {model.City}\r\nCountry: {model.Country}\r\nSubject: {model.Subject}\r\nMessage: {model.Message}";
// Configure your SMTP settings
string smtpServer = "mail.bluedotme.com";
int smtpPort = 465; // Change to the appropriate port for your SMTP server
string username = "[email protected]"; // Replace with your email address
string password = "*********"; // Replace with your email password
// Create an instance of SmtpClient
using (SmtpClient smtpClient = new SmtpClient(smtpServer, smtpPort))
{
smtpClient.EnableSsl = true; // Enable SSL/TLS
smtpClient.UseDefaultCredentials = false; // Disable default credentials
// Set your authentication details
smtpClient.Credentials = new NetworkCredential(username, password);
// Send the email
smtpClient.Send(message);
}
}
private void SendThankYouEmail(ContactViewModel model)
{
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]"); // Replace with your business email address
message.To.Add(model.Email);
message.Subject = "Thank You for Contacting Us";
message.Body = "Thank you for contacting us. We will get back to you soon.";
// Configure your SMTP settings
string smtpServer = "smtpout.secureserver.net";
int smtpPort = 465; // Change to the appropriate port for your SMTP server
string username = "[email protected]"; // Replace with your email address
string password = "*********"; // Replace with your email password
// Create an instance of SmtpClient
using (SmtpClient smtpClient = new SmtpClient(smtpServer, smtpPort))
{
smtpClient.EnableSsl = true; // Enable SSL/TLS
smtpClient.UseDefaultCredentials = false; // Disable default credentials
// Set your authentication details
smtpClient.Credentials = new NetworkCredential(username, password);
// Send the email
smtpClient.Send(message);
}
}
}
}
我添加了端口设置如下:
Outgoing Server:mail.bluedotme.com
SMTP Port: 465
请让我知道我如何克服这样的问题?
我试图像已经发布的回复一样做到最好,但我仍然无法弄清楚问题所在
答: 暂无答案
评论