0

嗨,在我的 Web 应用程序中,我们正在向不希望发件人作为电子邮件 ID 的人发送邮件,该s birthday is in current week, so while sending mail i don电子邮件 ID 用于 smtp 配置,我想使用不同的电子邮件 ID 作为发件人,

谁能告诉我如何实现这一目标,

4

1 回答 1

0
    /// <summary>
    /// Sends mail with authentification
    /// </summary>
    /// <param name="recipients"></param>
    /// <param name="from"></param>
    /// <param name="subject"></param>
    /// <param name="body"></param>
    /// <param name="isHTMLbody"></param>
    /// <param name="SMTPhost"></param>
    /// <param name="priority"></param>
    /// <param name="credentials"></param>
    /// <param name="port"></param>
    /// <param name="enableSsl"></param>
    public static void SendMailWithAuthentication(List<string> recipients, string from, string subject, string body, bool isHTMLbody,
        string SMTPhost, System.Net.Mail.MailPriority priority, System.Net.NetworkCredential credentials, int? port, bool enableSsl)
    {
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
        foreach (string recipient in recipients)
        {
            message.To.Add(recipient);
        }
        message.SubjectEncoding = Encoding.UTF8;
        message.BodyEncoding = Encoding.UTF8;
        message.Subject = subject;
        message.From = new System.Net.Mail.MailAddress(from);
        message.IsBodyHtml = isHTMLbody;
        message.Body = body;
        message.Priority = priority;
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
        client.Credentials = credentials;
        client.Host = SMTPhost;
        if (port != null)
        {
            client.Port = (int)port;
        }
        client.EnableSsl = enableSsl;
        client.Send(message);
        message.Dispose();
    }

对于“发件人”参数,您可以根据需要使用任何电子邮件,因为它是有效的电子邮件地址。只是一个示例,它可能是“bill.gates2@microsoft.com”,它会起作用。

如果这不起作用,您应该联系您的电子邮件提供商,因为他们阻止您这样做。

于 2012-09-22T13:23:30.463 回答