如果我的电脑上没有安装IIS / SMTP代理,是否可以发送电子邮件?

时间:2015-04-13 06:05:22

标签: asp.net vb.net smtp

如果我的本地电脑没有安装IIS / SMTP代理,是否可以使用asp.net发送电子邮件。 PS我正在使用Windows 7

我已尝试过大量代码:这就是我目前使用的

    Dim message As New MailMessage("abc@xyz.com", "pqr.@xyz.com", "SUB: Testing email", "SENDING EMAIL VAI ASP.NET")
    Dim emailClient As New SmtpClient("XXX.XXX.XXX.XXX")
    emailClient.Send(message)
    MsgBox("Message Sent")

错误讯息:

无法建立连接,因为目标计算机主动拒绝它

[WebException:无法连接到远程服务器]

[SmtpException:发送邮件失败。]

2 个答案:

答案 0 :(得分:0)

SMTP不必安装在同一台服务器上,但应允许使用您的IP地址。

您也可以将Gmail与自己的帐户一起用作SMTP服务器。

答案 1 :(得分:0)

这是我正在使用的代码。 (这是C#,但你可以转换它)

static readonly string EmailSendFrom = System.Web.Configuration.WebConfigurationManager.AppSettings["emailSendFrom"];
static readonly string EmailDisplayName = System.Web.Configuration.WebConfigurationManager.AppSettings["emailDisplayName";
static readonly string EmailPassword = System.Web.Configuration.WebConfigurationManager.AppSettings["emailPassword"];

 public static void SendEmail(string emailHtmlContent, string emailRecipients, string emailSubject, bool addBbc)
        {
            var @from = EmailSendFrom;                               
            var to = emailRecipients;

            var mail = new MailMessage();
            mail.To.Add(to);
            mail.From = new MailAddress(@from, EmailDisplayName, System.Text.Encoding.UTF8);

            mail.Subject = emailSubject;
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body = emailHtmlContent;
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml = true;                       
            var client = new SmtpClient
            {
                Credentials = new System.Net.NetworkCredential(@from, EmailPassword),
                Port = 587,
                Host = "myhost.name.co.il",
                EnableSsl = false
            };

            client.Send(mail);
        }