在 aspnetboilerplate 中发送电子邮件不起作用

Email sending in aspnetboilerplate not working

这是设置:

AddSettingIfNotExists(EmailSettingNames.DefaultFromAddress, "abc@xyz.tech");
AddSettingIfNotExists(EmailSettingNames.DefaultFromDisplayName, "abc.tech Emailservice");
AddSettingIfNotExists(EmailSettingNames.Smtp.UserName, "abc@xyz.tech");
AddSettingIfNotExists(EmailSettingNames.Smtp.Domain, "abc.tech");
AddSettingIfNotExists(EmailSettingNames.Smtp.EnableSsl,"false");
AddSettingIfNotExists(EmailSettingNames.Smtp.Host, "webmail.abc.tech");
AddSettingIfNotExists(EmailSettingNames.Smtp.Port, "25");
AddSettingIfNotExists(EmailSettingNames.Smtp.Password, "gdfdgd");
AddSettingIfNotExists(EmailSettingNames.Smtp.UseDefaultCredentials, "false");

这是邮件发送代码:

// See "Update"

我遇到了这个异常:

Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server

更新

public class UserAppService // ...
{
    private readonly UserManager _userManager;
    private readonly RoleManager _roleManager;
    IRepository<User, long> _rep;
    private readonly IRepository<Role> _roleRepository;
    private readonly IPasswordHasher<User> _passwordHasher;
    public readonly IEmailSender _emailSender;

    public UserAppService(
        IRepository<User, long> repository,
        UserManager userManager,
        RoleManager roleManager,
        IRepository<Role> roleRepository,
        IPasswordHasher<User> passwordHasher, IEmailSender em)
        : base(repository)
    {
        _rep = repository;
        _userManager = userManager;
        _roleManager = roleManager;
        _roleRepository = roleRepository;
        _passwordHasher = passwordHasher;
        _emailSender = em;
    }

    [AbpAllowAnonymous]
    public override async Task<UserDto> Create(CreateUserDto input)
    {
        // CheckCreatePermission();

        var user = ObjectMapper.Map<User>(input);

        user.TenantId = AbpSession.TenantId;
        user.Password = _passwordHasher.HashPassword(user, input.Password);
        user.IsEmailConfirmed = false;

        CheckErrors(await _userManager.CreateAsync(user));

        if (input.RoleNames != null)
        {
            CheckErrors(await _userManager.SetRoles(user, input.RoleNames));
        }

        CurrentUnitOfWork.SaveChanges();

        try
        {
            await _emailSender.SendAsync("test@gmail.com", "sdfs", "sdfsd", false);
        }
        catch (Exception ex)
        {
        }

        return MapToEntityDto(user);
    }
}

这与 aspnetboilerplate 无关。正如错误所说 "This mail server requires authentication when attempting to send to a non-local e-mail address. "

可能的原因:

  • 电子邮件客户端未配置 SMTP 身份验证和服务器 是
  • 防火墙或电子邮件代理软件正在阻止进行 SMTP 身份验证
  • 电子邮件客户端配置的凭据不正确或与服务器设置不匹配。

您可以下载下面的应用程序来测试您的 smtp 设置。 http://www.alexnolan.net/software/SMTPProber.htm

成功发送电子邮件后,请在 aspnetboilerplate 中使用正确的设置。

This mail server requires authentication when attempting to send to a non-local e-mail address.

您的 SMTP 服务器 (related) 似乎有问题。

尝试向您自己或同一域中的其他用户发送电子邮件。

I can't send mail to other domains same domain it is working what will be the problem.

请联系您的 SMTP 服务器的系统管理员。

using smtp ordinary .net code it is working fine

您也可以使用 IEmailSender 发送 MailMessage