Email sending in aspnetboilerplate not working

五迷三道 提交于 2019-12-13 02:48:23

问题


This is the settings:

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");

This is the email sending code:

// See "Update"

I am getting this exception:

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

Update

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);
    }
}

回答1:


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

Looks like an issue with your SMTP server (related).

Try sending an email to yourself or another user in the same domain.

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

Contact the system administrator of your SMTP server.

using smtp ordinary .net code it is working fine

You can send a MailMessage using IEmailSender too.




回答2:


This has nothing to do with aspnetboilerplate. as the error says "This mail server requires authentication when attempting to send to a non-local e-mail address. "

Possible causes:

  • Email client is not configured for SMTP authentication and the server is
  • Firewall or email proxy software is preventing SMTP authentication from occurring
  • Email client has incorrect credentials configured or does not match server settings.

What you can do is download the application below to test your smtp settings. http://www.alexnolan.net/software/SMTPProber.htm

Once you send email successfully, use the correct settings in aspnetboilerplate.



来源:https://stackoverflow.com/questions/47236426/email-sending-in-aspnetboilerplate-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!