Send Error:不允许使用邮箱名称。 服务器响应为: You are not authorized to send mail, authentication is required

本文介绍如何使用ASP.NET 2.0的System.Net.Mail库通过163邮件服务器发送电子邮件,包括设置SMTP客户端、认证信息及解决权限错误的方法。
使用asp.net 2.0 中新的System.Net.Mail发送邮件,使用163邮件服务器时等其他服务器时可能会出现:“Send Error:不允许使用邮箱名称。 服务器响应为: You are not authorized to send mail, authentication is required”错误,以下程序中红色为特别需要主要的地方。
protected void Button1_Click(object sender, EventArgs e)
    
{
        System.Net.Mail.MailMessage message 
= new System.Net.Mail.MailMessage();
        
//收件人
        message.To.Add(txtMailAddress.Text);
        
//抄送
        foreach(string mailAddress in txtCopyAddress.Text.Split(','))
        
{
            
if (!string.IsNullOrEmpty(mailAddress))
            
{
                message.CC.Add(mailAddress);
            }

        }
        
        
//主题
        message.Subject = txtSubject.Text;

        message.From 
= new System.Net.Mail.MailAddress(fromAddress);
        message.Body 
= txtMailContents.Text;
        
//发送附件
        if (fulAttachment.HasFile)
        
{
            System.Net.Mail.Attachment attachment 
= new System.Net.Mail.Attachment(fulAttachment.PostedFile.FileName);
            message.Attachments.Add(attachment);
        }

        System.Net.Mail.SmtpClient smtp 
= new System.Net.Mail.SmtpClient(txtSMTPAddress.Text);
        smtp.Credentials 
= new System.Net.NetworkCredential(txtUserName.Text,txtPassword.Text);
        
        
//smtp.usedefaultcredentials = true;
          
        
try
        
{            
            smtp.Send(message);
            lblReturnMessage.Text 
= "Mail Send Success!";
        }

        
catch (System.Net.Mail.SmtpException ex)
        
{
            lblReturnMessage.Text 
= "Send Error:" + ex.Message;
        }

     }

 

如果选择了163的SMTP服务器,“smtp.163.com”,发件人必须是登录用户的163 email用户地址。

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.163.com");
smtp.Credentials 
= new System.Net.NetworkCredential("163emailaddress","emailpassword");

System.Net.Mail.MailMessage message 
= new System.Net.Mail.MailMessage();
message.From 
= new System.Net.Mail.MailAddress("163emailaddress@163.com");
### CAN J1939 Protocol Bootloader Implementation and Usage A bootloader designed for the CAN J1939 protocol facilitates firmware updates over a Controller Area Network (CAN) bus, adhering to the Society of Automotive Engineers' (SAE) standard J1939. This protocol is widely used in heavy-duty vehicles and off-road machinery where multiple electronic control units (ECUs) need reliable communication. #### Key Features of CAN J1939 Bootloaders The primary function of such bootloaders includes secure and efficient transfer of binary images from an external source to internal memory within ECUs. The process involves several critical steps: - **Initialization**: Establishes connection parameters like baud rate and node address. - **Authentication & Security Checks**: Ensures only authorized software can be uploaded by verifying digital signatures or checksums[^1]. - **Data Transfer**: Utilizes segmented message structures defined under SAE J1939 standards to handle large files across limited packet sizes efficiently. - **Verification**: After receiving all segments, performs integrity checks on received data before committing changes permanently into non-volatile storage areas. #### Example Code Snippet Demonstrating Basic Functionality Below demonstrates how one might implement part of this functionality using Python as pseudo-code: ```python import can # Assuming 'can' module handles low-level CAN operations def initialize_j1939_connection(): """Sets up initial settings required for communicating via J1939.""" bus = can.interface.Bus(channel='can0', bustype='socketcan') return bus def send_data_segment(segment_number, total_segments, payload): """Sends individual chunks of data according to J1939 specifications.""" frame_id = calculate_frame_id() msg = can.Message(arbitration_id=frame_id, data=[segment_number, total_segments] + list(payload), extended_id=True) try: bus.send(msg) print(f"Sent segment {segment_number}/{total_segments}") except Exception as e: print(e) bus = initialize_j1939_connection() for i in range(total_segments): current_payload = get_next_chunk_of_firmware(i) send_data_segment(i+1, total_segments, current_payload) ``` This example assumes that `calculate_frame_id()` returns appropriate identifiers based upon application layer requirements while `get_next_chunk_of_firmware(index)` retrieves successive portions of the new firmware image ready for transmission. --related questions-- 1. What are common security measures implemented during CAN J1939-based firmware upgrades? 2. How does error handling work when implementing a CAN J1939 compliant bootloader system? 3. Can you explain the role of PGNs (Parameter Group Numbers) specifically concerning bootloader communications? 4. In what scenarios would it make sense to use alternative protocols instead of J1939 for updating embedded systems remotely?
评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值