 |
|
VB.NET ช่วยหน่อยนะคับบบบขอร้อง เครียดมาหลายวันแล้วคับบบ TT__TT การส่งเมล์ Mail หน่อยนะคับบ รบกวนด้วยคับ ขอบคุนมากคับ |
|
 |
|
|
 |
 |
|
ท่านผู้มีความรุ้ช่วย ด้วยคับเครียดสุดดดด คือผมทำโปรแกรมส่งเมล์ แต่อยากให้เวลาส่งมี ProgressBar เวลาส่ง แล้วมีปุ่ม Pause พักชัวคราวการส่งแล้วส่ง ต่อได้อะคับ
ผมทำโปรแกรมส่งเมล์ แต่อยากให้เวลาส่งมี ProgressBar เวลาส่ง แล้วมีปุ่ม Pause พักชัวคราวการส่งแล้วส่ง ต่อได้อะคับ
โค้ด
Code (VB.NET)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim smtpserver As New SmtpClient
smtpserver.Credentials = New Net.NetworkCredential("[email protected]", "xxxxx")
smtpserver.Host = ComboBox1.Text
smtpserver.Port = "587"
Dim des As New TohomeCenter.EmCRMLib.Encryption
Dim mail As New MailMessage
Dim i As Integer
For i = 0 To dt.Rows.Count - 1
mail = New MailMessage
mail.From = New MailAddress("[email protected]")
mail.To.Add(New MailAddress(dt.Rows(i)("emailname")))
mail.Subject = txtSuject.Text
mail.Body = txtmess.Text.Replace("<!--Link-->", "<a href=""http://localhost:65150/TEST/frmemailcancel.aspx?email=" & des.EncryptString(Me.txtto.Text) & """ target=""_blank"">")
If Not txtAttachment.Text = Nothing Then
Dim Attach As Net.Mail.Attachment = New Net.Mail.Attachment(txtAttachment.Text)
mail.Attachments.Add(Attach)
End If
mail.IsBodyHtml = True
smtpserver.EnableSsl = True
smtpserver.Send(mail)
'Dim msg As String
'Dim title As String
'Dim style As MsgBoxStyle
'Dim response As MsgBoxResult
'msg = "Your Mail Has Been Sent"
'style = MsgBoxStyle.OkOnly
'title = "Mail Sent Conformation"
'response = MsgBox(msg, style, title)
'If response = MsgBoxResult.Ok Then
' Me.Label1.Text = " "
' Timer1.Stop()
' Timer1.Enabled = False
'End If
'MessageBox.Show("send mail ok")
ProgressBar1.Maximum = 100
MsgBox("ทำการส่ง E-mail เรียบร้อย", MsgBoxStyle.Information, "ขอบคุณ")
Next
Catch ex As Exception
MsgBox("error")
End Try
End Sub
Tag : .NET, Ms SQL Server 2005, Ms SQL Server 2008, VB.NET
|
ประวัติการแก้ไข 2012-06-13 10:19:39
|
 |
 |
 |
 |
Date :
2012-06-11 13:48:34 |
By :
boy_zadaza |
View :
1552 |
Reply :
12 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลายกระทู้แล้วน่ะครับ คือในทางปฏิบัติมันทำไม่ได้ หรือทำยากน่ะครับ 
|
 |
 |
 |
 |
Date :
2012-06-11 15:53:20 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่เคยทำแบบส่งหลายๆคนแบบนี้เคยทำแต่ส่งไปคนเดียว แล้วก็แล้วกัน
ลองทำแบบถึก ๆ ดูไหมล่ะ
ตอนลูปคนไหนส่งไปแล้วก็ไป update status ใน table ว่าคนนี้ส่งแล้ว status เป็น 1
พอกด pause ก็ ไปกำหนด session ให้รู้ว่าตอนนี้ pause อยู่น่ะ สมมุติชื่อ session pause
แล้วในลูปก่อนส่งก็เพิ่มคำสั่ง if ไว้ว่า ถ้า session pause =true ให้ return ไม่ต้องส่งอีก
พอกดส่งครั้งหน้าก็ select มาเฉพาะคนที่ status=0
|
 |
 |
 |
 |
Date :
2012-06-11 18:08:18 |
By :
bangbang111 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูนะครับโปรแกรมมีบัคนิดหน่อย
โปรแกรมไม่ได้ส่งเมล์นะครับแค่ลองเขียนเทสเฉยๆ

Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace AutoSendMail
{
public partial class Form1 : Form
{
int m_index;
bool m_stop;
List<string> m_email;
BackgroundWorker m_bg;
public Form1()
{
InitializeComponent();
m_email = new List<string>();
m_email.Add("[email protected]");
m_email.Add("[email protected]");
m_email.Add("[email protected]");
m_email.Add("[email protected]");
m_email.Add("[email protected]");
m_email.Add("[email protected]");
m_email.Add("[email protected]");
m_email.Add("[email protected]");
m_email.Add("[email protected]");
m_email.Add("[email protected]");
m_bg = new BackgroundWorker();
m_bg.DoWork += new DoWorkEventHandler(bg_DoWork);
m_index = 0;
m_stop = false;
progressBar1.Maximum = 10;
progressBar1.Step = 1;
}
void bg_DoWork(object sender, DoWorkEventArgs e)
{
while(true)
{
if (m_stop == true)
{
Thread.Sleep(1000);
continue;
}
if (m_index >= 10)
{
MessageBox.Show("Conpleted");
break;
}
progressBar1.BeginInvoke(new Action(() =>
{
progressBar1.Value = m_index + 1;
}));
label1.BeginInvoke(new Action(() =>
{
label1.Text = "Send mail to " + m_email[m_index];
}));
m_index++;
Thread.Sleep(1000);
}
}
private void button1_Click(object sender, EventArgs e)
{
m_stop = false;
if(m_bg.IsBusy == false)
m_bg.RunWorkerAsync();
}
private void button2_Click(object sender, EventArgs e)
{
m_stop = true;
}
}
}
|
ประวัติการแก้ไข 2012-06-12 00:53:53
 |
 |
 |
 |
Date :
2012-06-12 00:53:10 |
By :
pStudio |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีครับ vb ที่เครื่องพี่ไม่ได้ลง vb ไว้ครับ ลองหาเว็บที่แปลงจาก c# เป็น vb ดุนะครับพพี่เคเคยเห้นคนโพสอยู่ในเว้บนี้เละครับ
|
 |
 |
 |
 |
Date :
2012-06-12 09:20:41 |
By :
pStudio |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แปลงเป็น VB.NET ให้ครับ
Code (VB.NET)
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Threading
Namespace AutoSendMail
Public Partial Class Form1
Inherits Form
Private m_index As Integer
Private m_stop As Boolean
Private m_email As List(Of String)
Private m_bg As BackgroundWorker
Public Sub New()
InitializeComponent()
m_email = New List(Of String)()
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_bg = New BackgroundWorker()
AddHandler m_bg.DoWork, New DoWorkEventHandler(AddressOf bg_DoWork)
m_index = 0
m_stop = False
progressBar1.Maximum = 10
progressBar1.[Step] = 1
End Sub
Private Sub bg_DoWork(sender As Object, e As DoWorkEventArgs)
While True
If m_stop = True Then
Thread.Sleep(1000)
Continue While
End If
If m_index >= 10 Then
MessageBox.Show("Conpleted")
Exit While
End If
progressBar1.BeginInvoke(New Action(Function()
progressBar1.Value = m_index + 1
End Function))
label1.BeginInvoke(New Action(Function()
label1.Text = "Send mail to " & m_email(m_index)
End Function))
m_index += 1
Thread.Sleep(1000)
End While
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
m_stop = False
If m_bg.IsBusy = False Then
m_bg.RunWorkerAsync()
End If
End Sub
Private Sub button2_Click(sender As Object, e As EventArgs)
m_stop = True
End Sub
End Class
End Namespace
|
 |
 |
 |
 |
Date :
2012-06-12 09:29:38 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|