iT邦幫忙

1

asp.net Core Web 每日自動發信一問

  • 分享至 

  • xImage

這聽起來不是一件困難的事,不過不知道有沒有辦法直接在Web做到
而不是使用sql或者Windows的排程來做

要在Web做一個按鈕,每天去點擊按鈕發送信件也是可以,不過不太實際
不知道有沒有人有這種經驗

我有Google到黑大這種方法
https://blog.darkthread.net/blog/aspnet-core-background-task/

還有沒有類似的方法可參考呢?感謝~

看更多先前的討論...收起先前的討論...
powerc iT邦新手 1 級 ‧ 2021-06-01 16:21:24 檢舉
quartz套件可以參考看看
To powerc: 好的,我在黑大的那篇留言也有看到此套件,尚未研究,感謝
小魚 iT邦大師 1 級 ‧ 2021-06-01 19:16:56 檢舉
網頁有點難吧.
YoChen iT邦研究生 1 級 ‧ 2021-06-02 11:05:34 檢舉
我自己的做法是Console Application+Windows排程每天啟動一次。
純寫Console Application監控時間定期發也是可以,但實在是多此一舉~XDDD
Web的話,真的不要拿來做排程((誠心建議
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
2
純真的人
iT邦大師 1 級 ‧ 2021-06-01 15:28:01

恩@@..我是寫簡單的Winform + Window排程方式~去觸發網頁發送...

Winform 內容如下..

Imports System.IO

Public Class Form1

    Public Update_Url As String = ""

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        '設定表單初始顯示位置
        Me.CenterToScreen()

        Me.MaximizeBox = False

        Me.FormBorderStyle = FormBorderStyle.FixedSingle

        '取得更新網址
        If File.Exists(Application.StartupPath & "\View_Url.txt") Then
            Update_Url = System.IO.File.ReadAllText(Application.StartupPath & "\View_Url.txt")
        End If
        If Update_Url <> "" Then
            Me.WebBrowser1.Navigate(Update_Url)
        Else
            Me.WebBrowser1.Navigate("about:尚未設定指定網址!")
        End If

    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Me.TextBox1.Text = WebBrowser1.Url.ToString
        Timer1.Interval = 3000
        Timer1.Enabled = True

    End Sub

    '設定3秒後關掉
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Me.Close()
    End Sub
End Class

觸發要定期執行的功能頁
https://ithelp.ithome.com.tw/upload/images/20210601/200613694fkXQpm2in.png

故每做一種要定期執行的網頁~我只要去改記事本的網址就好了@@"
例如這樣..
https://ithelp.ithome.com.tw/upload/images/20210601/20061369U9AlbcKhcB.png

喔不~~~還是用到Windows排程了
我也不太會Winform

您這個的意思大致上,是時間到會去執行這個網址列
然後這個Winform程式是持續開著的?~

因為Windows排程是最簡單的做法@@"

我的Winform是執行指定網址瀏覽
瀏覽3秒後關掉程式~
避免一直開著浪費記憶體
主要是要觸發定期執行的功能@@"

如果你要的話~我也可以把這支程式給你~
你只要改記事本的瀏覽網址就好了~

畢竟程式裡還加排程寫法就有點維護複雜了..

1
daylern0413
iT邦新手 5 級 ‧ 2021-06-01 15:52:41
public class Class1 {
    static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
    static int alarmCounter = 1;
    static bool exitFlag = false;
 
    // This is the method to run when the timer is raised.
    private static void TimerEventProcessor(Object myObject,
                                            EventArgs myEventArgs) {
       myTimer.Stop();
 
       // Displays a message box asking whether to continue running the timer.
       if(MessageBox.Show("Continue running?", "Count is: " + alarmCounter, 
          MessageBoxButtons.YesNo) == DialogResult.Yes) {
          // Restarts the timer and increments the counter.
          alarmCounter +=1;
          myTimer.Enabled = true;
       }
       else {
          // Stops the timer.
          exitFlag = true;
       }
    }
 
    public static int Main() {
       /* Adds the event and the event handler for the method that will 
          process the timer event to the timer. */
       myTimer.Tick += new EventHandler(TimerEventProcessor);
 
       // Sets the timer interval to 5 seconds.
       myTimer.Interval = 5000;
       myTimer.Start();
 
       // Runs the timer, and raises the event.
       while(exitFlag == false) {
          // Processes all the events in the queue.
          Application.DoEvents();
       }
    return 0;
    }
 }

https://docs.microsoft.com/zh-tw/dotnet/api/system.windows.forms.timer?view=netcore-3.1

咦...這好像可以耶

1
dscwferp
iT邦高手 1 級 ‧ 2021-06-01 16:18:05

<meta http-equiv="refresh" content="5" />
自動Refresh網頁,每隔5秒就會自己更新一次。

這種 舊的方法可以達成您的需求喔!
比如
再aspx header 加入
<meta http-equiv="refresh" content="86400" />
就會每隔 86400秒=1天 就會reload 自己aspx 一次
您的aspx 寫 reload 就發送信件
這樣就可以每天發送信件了!
簡單一行收工!

這好像也是一招,有點土法煉鋼XD

dscwferp iT邦高手 1 級 ‧ 2021-06-01 17:21:57 檢舉

土法煉鋼!!!
新工具 sql或者Windows的排程 您不要
給您舊工具 是 土法煉鋼!!!
嘆~~~

dscwferp iT邦高手 1 級 ‧ 2021-06-01 19:05:46 檢舉

還有 最新的方法:
使用 Google Apps Script 來 每日 連您的ASPX
這樣也可以每天發送信件了!
要用嗎?

1
PPTaiwan
iT邦好手 1 級 ‧ 2021-06-01 16:43:31

用 SQL CLR 的方式如何呢?? 我是用 CLR 的方式來做..

DLL 只做傳遞 Email 的動作,再用 SQL Agent 去執行排程並寄件,執行上有任何問題也可以很快就可以了解與排除問題。

這個方法有sql權限問題,我的專案不允許QQ

我要發表回答

立即登入回答