0

クライアントのコンピューターからメールを送信する必要があるアプリを構築しています

public static void sendMailLocal(string mailSubject, string userMail, string mailBody)
{
    try
    {
        string cliantMail = userMail;
        string subject = mailSubject;
        string body = string.Format("user email:{0}\n{1}",cliantMail,mailBody);
        string email;
        string password;
        string host;
        email = getMailAddrese();
        password = getPassword();
        host = getHostName();           
        var fromAddress = new MailAddress(email, "From Name",ncoding.Unicode);
        var toAddress = new MailAddress(email, "To Name");
        string fromPassword = password;
        SmtpClient smtp = new SmtpClient
        {
            Host = host,
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new tworkCredential(fromAddress.Address,fromPassword)
        };

        using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body
            })
        {
          smtp.Send(message);
        }
    }
    catch (Exception ex)
    {

    }
}

現在、このコードは一部のコンピューターで機能し、他のコンピューターではクラッシュします。調査の結果、名前が英語の場合は正常に動作することがわかりましたが、コンピューター名がヘブライ語の場合はクラッシュします。

では、コンピュータ名に関係なくメールを送信できる方法を知っている人はいますか?

私が得るエラーは、system.net.mail.smtpexception メール送信失敗 system.formatexception です。

smtp.send(message); で取得します。

4

0 に答える 0