相关疑难解决方法(0)

通过Gmail在.NET中发送电子邮件

我没有依赖我的主机发送电子邮件,而是考虑使用我的Gmail帐户发送电子邮件.这些电子邮件是我在节目中播放的乐队的个性化电子邮件.有可能吗?

.net c# email gmail smtp

852
推荐指数
18
解决办法
53万
查看次数

System.Net.Mail发送超时

我有一些较旧的代码可以很好地发送电子邮件,但是Visual Studio告诉我该代码已过时,我应该将其更改为Net.Mailfrom Web.Mail。我已经重写了大部分内容,但是我有几个问题。

这是原始的工作代码:

public void Send(string from, string to, string subject, string body, bool isHtml, string[] attachments)
{

    var mailMessage = new MailMessage

    {
        From = from,
        To = to,
        Subject = subject,
        Body = body,
        BodyFormat = isHtml ? MailFormat.Html : MailFormat.Text
    };


    // Add attachments
    if (attachments != null)
    {
        foreach (var t in attachments)
        {
            mailMessage.Attachments.Add(new Attachment(t));
        }
    }
    mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
    mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", _accountName);
    mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", _password);
    mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", _port.ToString(CultureInfo.InvariantCulture)); 
    mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", true);

    SmtpMail.SmtpServer = _smtp;
    SmtpMail.Send(mailMessage); …
Run Code Online (Sandbox Code Playgroud)

c# system.net.mail system.web.mail asp.net-mvc-4

3
推荐指数
1
解决办法
1万
查看次数