简体   繁体   中英

I'm trying to send sms to mobile via c# coding for my project but its not working for me

using System.Web;
using System.Net.Mail;
using System.Net;

namespace hash
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string toPhoneNumber = "DestinationPhoneNumber";
            string login = "id"; 
            string password = "pwd";
            string body = "Your Message";
            string To = toPhoneNumber + "@sms.ipipi.com";
            string From = login + "@ipipi.com";
            MailMessage mail = new MailMessage(From, To);
            mail.Body = body;
            SmtpClient smtp = new SmtpClient();
            SmtpClient client = new SmtpClient("ipipi.com",25);
            smtp.Credentials = new NetworkCredential(login,password);
            System.Security.Permissions.SecurityAction sa = new System.Security.Permissions.SecurityAction();
            SmtpPermissionAttribute smp = new SmtpPermissionAttribute(sa);
            try{
                 smtp.Send(mail);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }

Try:

SmtpClient smtp = new SmtpClient("ipipi.com",25);
//SmtpClient client = new SmtpClient("ipipi.com",25);

Hope that helps...

as @daryal mentions, you're creating two different clients. You need to merge them into a single client.

    SmtpClient smtp = new SmtpClient("ipipi.com",25);
    smtp.Credentials = new NetworkCredential(login,password);
    System.Security.Permissions.SecurityAction sa = new System.Security.Permissions.SecurityAction();
    SmtpPermissionAttribute smp = new SmtpPermissionAttribute(sa);
    try{
         smtp.Send(mail);
    }

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