Asp.net 使用SMTP服务器发送邮件

Asp.net 使用SMTP服务器发送邮件,asp.net,Asp.net,该死的家伙 我已使用SMTP服务器发送邮件,如下所示 public bool SendMail(string mailFrom, string mailTo, string mailCC, string mailBCC, string subject, string body, string attachment, bool isBodyHtml) { bool SendStatus = false; System.Net.Mail.MailMessage mailMesg =

该死的家伙

我已使用SMTP服务器发送邮件,如下所示

 public bool SendMail(string mailFrom, string mailTo, string mailCC, string mailBCC, string subject, string body, string attachment, bool isBodyHtml)
{
    bool SendStatus = false;
    System.Net.Mail.MailMessage mailMesg = new System.Net.Mail.MailMessage(mailFrom, mailTo);

    if (mailCC != string.Empty)
        mailMesg.CC.Add(mailCC);

    if (mailBCC != string.Empty)
        mailMesg.Bcc.Add(mailBCC);

    if (!string.IsNullOrEmpty(attachment))
    {
        System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(attachment);
        mailMesg.Attachments.Add(attach);
    }
    mailMesg.Subject = subject;
    mailMesg.Body = body;
    mailMesg.IsBodyHtml = isBodyHtml;
    mailMesg.ReplyTo = new System.Net.Mail.MailAddress(mailFrom);

    System.Net.Mail.SmtpClient objSMTP = new System.Net.Mail.SmtpClient();


    string Host = System.Configuration.ConfigurationManager.AppSettings["MailHost"].ToString();
    string UserName = System.Configuration.ConfigurationManager.AppSettings["MailUserId"].ToString();
    string password = System.Configuration.ConfigurationManager.AppSettings["MailPassword"].ToString();


    objSMTP.Host = Host;
    objSMTP.Port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"].ToString());
    objSMTP.Credentials = new System.Net.NetworkCredential(UserName, password);


    objSMTP.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

    try
    {
        objSMTP.Send(mailMesg);
        SendStatus = true;
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        mailMesg.Dispose();
        mailMesg = null;
    }


    return SendStatus;

}
我想知道,有没有可能发送没有用户名和密码的邮件?
如果可能的话,有人能建议我怎么做吗,如果您的smtp服务器不需要认证,您不应该指定em。否则您应该指定。

我认为您需要将您要发送电子邮件的ip列为白名单,该ip将作为您的服务器,并且此选项在您要发送电子邮件的邮件帐户上完成